← 返回 uber 的题目列表Paint Line and Count Adjacent Same Colors
类型:online_judge
On an infinitely long number line labeled 0, 1, 2, ..., n, each point can be colored. Coloring means assigning a number to each node. Implement a function to calculate the total number of pairs of adjacent positions that have the same color after coloring.
Input Format:
An integer n, representing the total number of points to be colored.
The next n lines each contain two integers i, c, indicating that point i is colored with color c.
Output Format:
Output an integer representing the count of adjacent pairs with the same color.
Example:
Input:
3
2 1
3 1
4 2
Output:
1
Explanation: Points 2 and 3 are colored the same, thus there is 1 pair of adjacent positions with the same color.
Example
Input
3
2 1
3 1
4 2