#K3276. Counting Balloon Groups
Counting Balloon Groups
Counting Balloon Groups
You are given a string S representing a sequence of balloons. Each balloon is in one of two states: popped (represented by the character 'p') or intact (represented by the character 'i'). A balloon group is defined as a popped balloon together with its immediate intact balloon neighbor(s) if they exist. Formally, if a balloon at position (k) is popped (i.e. S[k] = 'p'), it forms a group along with the balloon at position (k-1) if (S[k-1] = 'i') and/or the balloon at position (k+1) if (S[k+1] = 'i'). Note that even if an intact balloon is adjacent to two popped balloons, each popped balloon is considered to form its own group. Your task is to count the total number of such groups in the given sequence.
For example, given the input ipipi
, there are 2 groups since there are two popped balloons at positions 2 and 4 (using 1-indexing) each possibly attaching to an intact neighbor.
inputFormat
The input consists of a single line containing a string S which represents the sequence of balloons. Each character in S is either 'p' (popped) or 'i' (intact).
outputFormat
Output a single integer representing the total number of balloon groups formed as defined.## sample
p
1
</p>