10199 - Problem 1   

Description

The input is a string of letters, for example,

BbBTTtttTUuUuUUuUuUukk

Find the length of the longest consecutive lowercase letters. For the above example, the answer is 3, because the longest consecutive letters are ttt.

Hint:
I. Use while((ch=getchar())!='\n') { … } to read the input data.
II. Use another variable prev to remember the previous letter.
III. Include ctype.h so that you can use islower(ch) to check if ch is lowercase.
IV. The algorithm can be summarized as follows:
while loop: read the current letter and do the loop when the letter is not '\n'

i)       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

ii)     else

a.  if islower(ch), then 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 lowercase letters. Be sure to add a newline character '\n' at the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss