#include <string.h>
#include <stdio.h>
int main() {
char str[100];
int count[26] = { 0 }, i = 0;
printf("input a string: \n");
gets(str);
while (str[i]!='\0')
{
if (str[i] >= 'a' && str[i] <= 'z')
count[str[i] - 'a']++;
else if (str[i] >= 'A' && str[i] <= 'Z')
count[str[i] - 'A']++;
i++;
}
printf("result:\n");
for (i = 0; i < 26; i++) {
if (count[i] != 0) {
printf("%c - %d\n", i + 'A', count[i]);
}
}
return 0;
}
成都信息工程大学研究生考试2018年读代码第一题。
输入:This is a test program! 123OK
结果: