杭电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;
}

 

posted @ 2011-10-22 19:50  爱生活,爱编程  阅读(217)  评论(0编辑  收藏  举报