#115. 统计数组中的连续相同元素块

    ID: 115 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-3gesp2模拟循环嵌套

统计数组中的连续相同元素块

Count Clumps in Array

Background

Congcong is organizing a batch of data. He noticed that some data elements are consecutively repeated, and he wants to know how many such consecutive blocks there are.

Problem Description

Say that a "clump" in an array is a series of 2 or more adjacent elements of the same value. Return the number of clumps in the given array.

Input Format

Input is given from standard input in the following format.

An integer array, where elements are separated by spaces and enclosed in square brackets.

Output Format

Output is printed to standard output in the following format.

A single integer, representing the number of clumps in the array.

Sample

[1 2 2 3 4 4]
2
[1 1 2 1 1]
2
[1 1 1 1 1]
1

Sample Explanation

Sample 1: In the array [1 2 2 3 4 4], 2 2 is one clump and 4 4 is another clump, totaling 22 clumps.

Sample 2: In the array [1 1 2 1 1], the first 1 1 is one clump, and the second 1 1 is another clump, totaling 22 clumps.

Sample 3: In the array [1 1 1 1 1], all 1s form a single clump, totaling 11 clump.

Constraints

Time limit: 11 second, Memory limit: 10241024 KiB for each test case.