hdu1020

来源:互联网 发布:java复试 编辑:程序博客网 时间:2024/06/05 16:10

点击打开链接

大笑大笑水题

注释:用一个变量k统计每个字母出现的次数,当该子母出现的次数统计完时,若k>1,则输出k和字母。


#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;


int main()
{
    int n;
    char s[10005];
    cin>>n;
    while(n--)
    {
        cin>>s;
        int lenth=strlen(s),k=1;
        char temp=s[0];
        for(int i=1;i<lenth+1;i++)
        {
            if(temp==s[i])
                k++;
            else
            {
                if(k!=1)
                printf("%d",k);
                printf("%c",temp);
                temp=s[i];
                k=1;
            }
        }
       printf("\n");
    }
    return 0;
}

0 0
原创粉丝点击