您的位置:首页 > 其它

杭电 1020 Encoding

2017-11-26 21:12 357 查看
这道题很水,没看懂题目时觉得挺复杂的,又要输出数字又要输出字母。于是尝试分开输出然就成功通过了。

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: