标签: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
cin>>str; len=strlen(str); for (i=0;i<=len-1;i++) { t=int(str[i]-‘a‘+1); num[t]++; } best=0; b=0; for (i=1;i<=26;i++) {if (num[i]>best) {best=num[i];}} cout<<best;
明显错的节奏
这个是我10分钟的代码,似乎是正解:.
cin>>str; i=0; best=0; while (i<strlen(str)) { t=i; ch=str[i]; while ((t<=strlen(str))&&(str[t]==ch)) t++; best=max(best,t-i); i=t+1; } cout<<best<<endl;
然而没过肯定有问题
可是我怎么测都没发现
感谢暖阳(fpcsong)巨大牛。。一个数据搞定:
1
abbc
正解应该是2,可是我答案是1.。。。。。
其实原因在这儿:
i=t+1
应该写:
i=t
哭死啊。。。。。。。。。。。
位处理的时候一定要多看几遍。。。。。。。。
上正解
#include<iostream> #include<cstdlib> #include<cstdio> #include<cstring> using namespace std; char str[200]; char ch; int len,best,i,t,b,j,all; int main() { cin>>all; for (j=1;j<=all;j++){ cin>>str; i=0; best=0; while (i<strlen(str)) { t=i; ch=str[i]; while ((t<=strlen(str))&&(str[t]==ch)) t++; best=max(best,t-i); i=t; } cout<<best<<endl; } return 0; }
RunID | 用户 | 问题 | 判决 | 时间 | 内存 | 朗 | 长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
14306 | seekdreamer | D | Accepted | 0 MS | 1672 KB | C++ | 388 B | 2014-06-08 23:13:06 |
再次感谢耐心帮我调出来的暖阳(fpcsong)巨大牛。。。
一道字符串水题LSS(ACdream),布布扣,bubuko.com
标签:des c style class blog code
原文地址:http://www.cnblogs.com/seekdreamer/p/3777008.html