#include <stdio.h>
#include <stdlib.h>
#include<string.h>
//1020
int main()
{
int n,count=1,i;
char c[10001];
scanf("%d",&n);
getchar();
while(n>0)
{
gets(c);
int length;
length=strlen(c);
for(i=0;i<length;i++)
{
if(c[i]==c[i+1])
count++;
else
{ if(count>1)
{
printf("%d%c",count,c[i]);
count=1;
}
else
printf("%c",c[i]);
}
}
printf("\n");
n--;
}
return 0;
}
编码方式 1020
1 问题描述
给定一个仅包含’A’-‘Z’的字符串,我们可以使用以下方法对其进行编码:
每个包含k个相同字符的子字符串应编码为“ kX”,其中“ X”是该子元素中的唯一字符-串。
如果子字符串的长度为1,则应忽略’1’。
2 输入
第一行包含一个整数N(1 <= N <= 100),它表示测试用例的数量。接下来的N行包含N个字符串。每个字符串仅包含’A’-‘Z’,并且长度小于10000。
3 输出
对于每个测试用例,在一行中输出编码的字符串。
4 样例输入
2
美国广播公司
ABBCCC
5 样例输出
美国广播公司
A2B3C