杭电 1020 Encoding

来源:互联网 发布:et服装软件图片 编辑:程序博客网 时间:2024/05/20 04:09

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

#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;}
原创粉丝点击