#include
#include
#include
using namespace std;
void print(int count, string temp)
{
if (count == 1)
cout << temp[0];
else
cout << count << temp[0];
}
int main(int argc, char argv[])
{
ifstream cin("F:\\test.txt");
int num;
string sPtr,temp;
cin >> num;
for (int i = 0; i < num; i++)
{
cin >> sPtr;
temp = sPtr[0];
int count = 0;
//本体的思路始终将sPtr中和前面不相同字母赋值给temp[0];
int length = sPtr.size();
for (int j = 0; j < length; j++)
{
if (temp[0] == sPtr[j])
{
//一定要注意是否已经到了字符串的尾部
count++;
if (j == sPtr.size() - 1)
{
print(count,temp);
}
}
else
{
print(count, temp);
temp[0] = sPtr[j];
count = 1;
if (j == length-1)
{
print(count, temp);
}
}
}
cout << endl;
sPtr = "";
}
return 0;
}
ZOJ 2478
最新推荐文章于 2017-04-19 18:54:30 发布