Description

输入一个由字母a~z或A~Z组成的字符串。您的任务就是,编程统计不区分大小写的相同字母个数,并输出统计后的字母数字串。输出时字母只能大写,且按A到Z的顺序。如果字符个数是1,则省略该数字。 例如,如果给出字符串eAaBbCacABcBC,统计知道E有1个、A有4个、B有4个、C有4个。于是,输出字母数字串为A4B4C4E。

Input

输入可以有多个测试用例。每个测试用例是一行由大小写字母组成的字符串(1<=串长<=200)。如果读入的字符串首字符为数字0,表示结束且该行不需要处理。

Output

每个测试用例输出一行,即统计后的字母数字串,并按字母的ASCII码大小的顺序输出。

Sample Input

eAaBbCacABcBC 0ABCD

Sample Output

A4B4C4E
 
 
 
#include<stdio.h>
#include<string.h>
int main()
{
	char str[300];
	int i, j, t;
	while( gets(str) )
	{
		int len, t = 0, count = 0;
		len = strlen( str );
        int num1[30]={0}, num2[30]={0},sum[30]={0};
        if( str[0] == '0' )
             break;
        else
        {
          for( i = 0; i < len; i++ )
             {
                  if( str[i] >= 'a' && str[i] <= 'z' )
                  {
                       num1[ str[i] - 'a' ]++;
                  	   	count++;
                   }
                  else if(str[i] >= 'A'&&str[i]<='Z')
                  {
                      num2[str[i]-'A']++; 
           		       t++; 
           		  }
              }
            for( i = 0; i < 26; i++ )
            {
                sum[i] = num1[i]+num2[i];
                if(( sum[i] != 0 )&&(sum[i]!=1))
                    printf( "%c%d", 'A' + i, sum[i] );
                else if( sum[i] == 1 )
                     printf( "%c", 'A'+i );
             }
                printf( "\n" );
         }         
	}
}
posted on 2011-11-26 21:37  狸の舞  阅读(182)  评论(0编辑  收藏  举报