您的位置:首页 > 其它

ZOJ 2478 Encoding

2011-12-22 22:41 218 查看
#include "iostream"
#include "string"
using namespace std;

int main()
{
int TestCase;
cin >> TestCase;
while (TestCase--)
{
string str, first;
int length, count = 0;
cin >> str;
length = str.size();
first = str[0];
for (int i = 0; i < length; i++)
{
if (str[i] == first[0])
{
count++;
if (i == length - 1)
{
if (count == 1)
cout << first;
else
cout << count << first;
}
}
else
{
if (count == 1)
cout << first;
else
cout << count << first;
first = str[i];
count = 1;
if (i == length - 1)
{
if (count == 1)
cout << str[i];
else
cout << count << str[i];
}
}
}
cout << endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: