View Code of Problem 36

#include <stdio.h>
#include <string.h>
int main()
{
	int T,n,i,j;
	char s[1000];
	scanf("%d\n",&T);
	while(T--)
	{
		int b[30]={0};    //必须初始化b数组,不然会出错
        char a[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//a数组在定义时就要初始化
		scanf("%s",s);
		n=strlen(s);
		for(i=0;i<n;i++)
		{
			for(j=0;j<26;j++)
			{
				if(s[i]==a[j])
			   {
				   //b[j]=b[j]+1;
				   b[j]++; 
			   }
			}	
		}
		for(i=0;i<26;i++)
		{
			if(b[i]!=0){
				printf("%d%c",b[i],a[i]);//输出中间没有空格(不像输入)
			}	
		}
		printf("\n");	
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 36