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, sum[27] = {0};
	scanf("%d\n", &T);
	while(T--)
	{
	    gets(str);
	    for(int i = 0; i < strlen(str); i++)
		{
		    for(int j = 0; j < 27; j++)
			{
		    	if(str[i] == a[j])
		     		sum[j]++;
			}
		}
		for(i = 0; i < 27; i++)
		{
			if(sum[i] != 0)
			{
				printf("%d%c", sum[i], a[i]);
			}
		}
		printf("\n");
	}
	return 0;
}
/*
Main.c: In function 'main':
Main.c:11:6: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
      gets(str);
      ^
Main.c:20:7: error: 'i' undeclared (first use in this function)
   for(i = 0; i < 27; i++)
       ^
Main.c:20:7: note: each undeclared identifier is reported only once for each function it appears in
*/

Double click to view unformatted code.


Back to problem 36