水题
注释:用一个变量k统计每个字母出现的次数,当该子母出现的次数统计完时,若k>1,则输出k和字母。
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int n;
char s[10005];
cin>>n;
while(n--)
{
cin>>s;
int lenth=strlen(s),k=1;
char temp=s[0];
for(int i=1;i<lenth+1;i++)
{
if(temp==s[i])
k++;
else
{
if(k!=1)
printf("%d",k);
printf("%c",temp);
temp=s[i];
k=1;
}
}
printf("\n");
}
return 0;
}