http://acm.hdu.edu.cn/showproblem.php?pid=1020
=w= 比较简单啦。
一开始用一个字符串保存结果,然后输出。结果WA了。
然后改成边统计边输出就对了。不知道为什么=w=
#include <iostream>
#include <string.h>
using namespace std;
#define LEN 10005
char s[LEN];
int main(){
#ifndef ONLINE_JUDGE
freopen("1020in.txt","r",stdin);
#endif
int t,i,c;
scanf("%d",&t);
while (t--){
scanf("%s",s);
for (i=0;i<=strlen(s);i++){ //s[strlens(s)]='\0',未越界.
if (i==0)
c=1;
else if (s[i]==s[i-1])
c++;
else {
if (c!=1)
printf("%d",c);
printf("%c",s[i-1]);
c=1;
}
}
putchar(10);
}
return 0;
}
本文介绍了解决HDU 1020问题的一种有效方法。通过使用C++编程语言,作者分享了一个避免缓冲区溢出的技巧,并解释了如何在处理字符串时进行边统计边输出的方法。
323

被折叠的 条评论
为什么被折叠?



