1020:Encoding

来源:互联网 发布:windows 系统更新慢 编辑:程序博客网 时间:2024/05/22 01:55

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1020

方法:硬做

思路:一开始想用hash统计各个字符出现的次数,但是后来发现领会错题意了,于是乎干脆就按照题意大模拟了。这个题要说难一点的地方,那就是首末端的边界处理了。

难点:首末端边界,可以先让出首端,单独处理末端数据。

#include<iostream>#include<string>using namespace std;int main(){    int n;    while(cin>>n)    {        while(n--)        {            int hashset[26] = {0};            string s;            cin>>s;            int sum = 1;            for(int i = 1;i < s.length();i++)            {                if(s[i] == s[i-1])                    sum++;                if(s[i] != s[i-1])                {                    if(sum == 1)                        cout<<s[i-1];                    else                        cout<<sum<<s[i-1];                    sum = 1;                }                if(i == s.length()-1)                    if (sum == 1)                        cout<<s[i];                    else                        cout<<sum<<s[i];            }            cout<<endl;        }    }}


0 0
原创粉丝点击