Why Did the Cow Cross the Road 1
InterviewTime limit2sMemory limit512 MB
Given observations of which side of the road each of 10 cows stands on, count how many times a cow changes sides between consecutive observations of that cow.
- Level
Easy3 of 10
- Topics
- Array, Implementation, Simulation, Hash map
- Solved
- No attempts yet
Problem
Why the chicken crossed the road has been studied in scientific depth, but surprisingly little research exists on why the cow crossed the road. Farmer John has long been interested in this topic, and a university has now offered him a research project on why cows cross the road.
John's job is to watch cows cross the road. He observes cow positions times. Each observation consists of one cow number and one position for that cow. John owns 10 cows, so a cow number is an integer from 1 to 10, and a position is either 0 or 1, meaning the left or the right side of the road.
Using this observation record, find the minimum number of times the cows crossed the road. In other words, count how many times a cow with the same number changed its position.
Input
The first line contains the number of observations , a positive integer not greater than 100.
Each of the next lines contains one observation, in the order the observations were made. An observation consists of a cow number and a position (0 or 1).
Output
Print the minimum number of times the cows crossed the road on the first line.
Hint
In the sample, cow 3 was observed at positions 1, 0, 1 in that order, so it crossed the road at least twice. Cow 4 crossed the road once, and there is no record of any other cow crossing.