10196 - Length of the longest repeat letters   

Description

The input is a string of letters, for example,

BbBTTttTUuuUUUkk

Find the length of the longest repeat letters. For the above example, the answer is 6, because the longest repeat letters are UuuUUU. Note that we do not have to distinguish uppercases from lowercases, that is, U and u are considered the same.

Hint:
a. Use while((ch=getchar())!='\n') { … } to read the input data.
b. Use another variable prev to remember the previous letter.
c. Include ctype.h so that you can use toupper(ch) to convert ch into uppercase, and then you do not need to take care of the case because every letter is uppercase.
d. The algorithm can be summarized as follows:
while loop: read the current letter and do the loop when the letter is not '\n'

i)       convert the letter to uppercase

ii)     if the letter is different from the previous one

a.  compare the length of the current repeat letter with the longest length we have seen so far; if the length of the current letter is longer, then update the longest length as the new one.

b.  update the prev as ch

c.  reset the length of the current repeat letter as 1 because we start with a new letter

iii)    else 

 

a.  increase the length of the current repeat letter by 1

Input

The input is a string of English letters, which can be uppercase or lowercase. There are no whitespaces between the letters, and the input is ended with '\n'.

 

Output

The output is a number indicating the length of the longest consecutive letters. Be sure to add a newline character '\n' at the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss