杭电1020 Encoding

/********************************
 *    日期:2011-2-9
 *    作者:SJF
 *    题号:杭电1020
 *  题目:Encoding
 *    结果:AC
 *       注意:刚开始把count[10000]定义为char型,没看出来,一直wrong!
 ********************************/
#include<stdio.h>
#include<string.h>
int main()
{
    int N;
    //freopen("debug\\data.txt","r",stdin);
    while(scanf("%d\n",&N)!=EOF)
    {
        int k;
        for(k=0;k<N;k++)
        {
            char string[10000],c[10000];
            int count[10000];
            int len,i,j=0,num=0;
            gets(string);
            len=strlen(string);
            c[0]=string[0];
            memset(count,0,10000);
            for(i=0;i<len;i++)
            {
                if(c[j]==string[i])
                {
                    count[j]++;
                }
                else
                {
                    j++;
                    c[j]=string[i];
                    count[j]++;
                }
            }
            while(count[num]!=0)
            {
                if(count[num]==1)
                {
                    printf("%c",c[num]);
                }
                else
                {
                    printf("%d%c",count[num],c[num]);
                }
                num++;
            }
            printf("\n");
        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值