题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2886
Hint: 本题和ZOJ 2478 题目的思路比较接近,注意思维的严密性即可。
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<iterator>
#include<algorithm>
using namespace std;
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("D:\\in.txt", "r", stdin);
freopen("D:\\out.txt", "w", stdout);
#endif // ONLINE_JUDEG
int n(0);
cin >> n;
string str;
char t;
int temp(0);
for (int i = 0; i < n; i++)
{
temp = 0;
cin >> str;
t= str[0];
for (int j = 0; j < str.length(); j++)
{
if (str[j] == t)
{
temp++;
if (str.length() - 1 == j)//已是最后一个,直接输出
{
cout << temp << t;
}
}
else
{
cout << temp << t;
t = str[j];
temp = 1;
if (str.length() - 1 == j)//已是最后一个,直接输出
{
cout << "1"<< t;
}
}
}
cout << endl;
}
return 0;
}