题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1020
收获:
把数字以字符的形式输出:int k;char t[3];t[1]=k+'0'【这里的数字字符转换,限定数字的范围为0~9】,也就是这个地方错了。
我的代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main()
{char uu[10002]={0};
int n;
scanf("%d",&n);
getchar();
int i;
for(i=0;i<n;i++)
{
gets(uu);
int k=1;
int j;
for(j=0;j<strlen(uu);j++)
{
if(uu[j]==uu[j+1]){k++;continue;}
else if(uu[j]!=uu[j+1]){
if(k==1)printf("%c",uu[j]);
else {printf("%d%c",k,uu[j]);k=1;}
}
}
printf("\n");
}
return 0;
}