标签:des c style class blog code
Time flies, four years passed, colleage is over. When I am about to leave, a xuemei ask me an ACM problem, but I can‘t solve it, I am 功力尽失. Please help me so that I won‘t lose face in front of xuemei!
Give you a string , you should find the longest substring which is of the same character.
First line there is a T , represents the test cases.
next T lines will be T strings.
the length of every string is less than 100
all the characters of the strings will be lowercase letters
for each test case output a number
1 a
1
1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 int T,i;
8 cin>>T;
9 while(T--){
10 char a[101];
11 cin>>a;
12 //统计最长连续相同字符子串长度
13 int num=1,sum=1;
14 for(i=1;a[i];i++){
15 if(a[i]==a[i-1])
16 num++;
17 else
18 num=1;
19 if(num>sum)
20 sum=num;
21 }
22 cout<<sum<<endl;
23 }
24 return 0;
25 }
Freecode : www.cnblogs.com/yym2013
Acdream 1111:LSS(水题,字符串处理),布布扣,bubuko.com
标签:des c style class blog code
原文地址:http://www.cnblogs.com/yym2013/p/3777551.html