您的位置:首页 > 其它

zoj 2886 Look and Say

2011-12-23 12:02 337 查看
//这一题和2478差不多,只不过是字符串变长了,如果用cout频繁输出的情况下就会超时!所以用printf!
#include "iostream"
#include "string"
#include "stdio.h"
using namespace std;

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