HDU1020

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

找到同一个字母连续出现的次数,然后按顺序输出次数和字母,如果次数为1数字就不用输出

#include<iostream>
#include<cstring>

int main()
{
    char str[10001];
    int n;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%s",str);
        int i,count=1;
        for(i=0;i<strlen(str);i++)
        {
            if(str[i]==str[i+1]) 
                count++;
            else
            {
                if(count==1) printf("%c",str[i]);
                else printf("%d%c",count,str[i]);
                count=1;
            }
        }
        printf("\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/hjq_xidian/article/details/52691945
今日推荐