{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "print >> open(\"input-b.in\", \"w\"), \"\"\"5\n",
    "-\n",
    "-+\n",
    "+-\n",
    "+++\n",
    "--+-\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case #1: 2\r\n",
      "Case #2: 3\r\n",
      "Case #3: 3\r\n",
      "Case #4: 2\r\n",
      "Case #5: 4\r\n"
     ]
    }
   ],
   "source": [
    "def solve(s, f, case):\n",
    "    ans = len(filter(lambda x: x[0] != x[1], zip(s, s[1:] + '+')))\n",
    "    print >> f, 'Case #{}: {}'.format(case, ans)\n",
    "        \n",
    "def solve_file(filename):\n",
    "    i = 1\n",
    "    with open(filename + \".out\", 'w') as fout:\n",
    "        with open(filename) as fin:\n",
    "            for line in fin.readlines()[1:]:\n",
    "                solve(line.strip(), fout, i)\n",
    "                i += 1\n",
    "                \n",
    "solve_file(\"input-b.in\")\n",
    "!cat \"input-b.in.out\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
