hdu 1020 Encoding

来源:互联网 发布:开淘宝网店一件代发 编辑:程序博客网 时间:2024/05/29 11:08

Description

Given a string containing only 'A' - 'Z',we could encode it using the following method:

 

1. Each sub-string containing k samecharacters should be encoded to "kX" where "X" is the onlycharacter in this sub-string.

 

2. If the length of the sub-string is 1,'1' should be ignored.

 

Input

The first line contains an integer N (1<= N <= 100) which indicates the number of test cases. The next N linescontain N strings. Each string consists of only 'A' - 'Z' and the length isless than 10000.

 

Output

For each test case, output the encodedstring in a line.

 

Sample Input

2

ABC

ABBCCC

 

Sample Output

ABC

A2B3C


题意:输入字符串,输出格式为“数字-字符”,数字为该字符出现的次数。

若输入ABBAB,输出的应该是A2BAB,而不是2A3B


#include<stdio.h>#include<string.h>int main(){    int i,n,count,k;    char a[10001];    while(~scanf("%d",&n))    {        scanf("%s",a);        k=strlen(a);count=1;        for(i=0;i<k;i++)        {            if(a[i]==a[i+1])                count++;            else             {                if(count==1)                printf("%c",a[i]);            else                 printf("%d%c",count,a[i]);            count=1;            }        }        printf("\n");    }    return 0;}



0 0