这道题很水,没看懂题目时觉得挺复杂的,又要输出数字又要输出字母。于是尝试分开输出然就成功通过了。
#include<iostream>
#include <string>
using namespace std;
int main()
{
int m;
cin >> m;
while (m--)
{
char a[10000];
int b, n = 1;
cin >> a;
b = strlen(a);
char tem;
tem = a[0];
for (int i = 1; i < b; i++)
{
if (a[i] == tem)
{
n++;
}
else
{
if (n != 1)
cout << n << tem;
else
cout << tem;
n = 1;
tem = a[i];
}
}
if (n != 1)
cout << n << tem << endl;
else
cout << tem << endl;
}
return 0;
}