题目:http://acm.hdu.edu.cn/showproblem.php?pid=1020
经常WA请进来看看..............
就是题目表述有问题:字符算得是相邻的相同的个数
eg:如果碰到AABBBCCCABC的话,应该是2A3B3CABC
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int n,a;
char str[26];
string s;
cin>>n;
while(n--)
{
cin>>s;
s+='0';
for(int j=1,i=0;j<s.length();j++)
{
if(s[i]!=s[j])
{
a=j-i;
if(a==1)
cout<<s[i];
else
cout<<a<<s[i];
i=j;
}
}
cout<<endl;
}
return 0;
}