View Code of Problem 36

#include <stdio.h>
#include <string.h>
#define N 1000
int main()
{
	char str[N], a[27] = {'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'};
	int T, i, j;
	scanf("%d\n", &T);
	while(T--)
	{
		int sum[27] = {0};
	    gets(str);
	    for(i = 0; i < strlen(str); i++)
		{
		    for(j = 0; j < 27; j++)
			{
		    	if(str[i] == a[j])
		     		sum[j]++;
			}
		}
		for(i = 0; i <= 26; i++)
		{
			if(sum[i] != 0)
			{
				printf("%d%c", sum[i], a[i]);
			}
		}
		printf("\n");
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 36