字符统计2

字符统计2

字符统计2 | SDUT

#include <stdio.h>
#include<string.h>
int main() {
	char ch[100];
	while (gets(ch)) {//循环读入
		int st1[30] = {0};
		int st2[30] = {0};
		int len = strlen(ch);
		for (int i = 0; i < len; i++) {
			if ('A' <= ch[i] && ch[i] <= 'Z') {//ascii码较小,所以放在前面循环
				st2[ch[i] - 'A']++;//第一个字符减去a的大小,既可以存储在第二个数组的26个英文对应处。
			} else {
				st1[ch[i] - 'a']++;//小写字母的判断

			}

		}
		char x;
		int cnt = -9999;
		for (int i = 0; i < 28; i++) {
			if (cnt < st2[i]) {//存储大写字母的最小值
				cnt = st2[i];
				x = i + 'A';
			}
		}
		for (int i = 0; i < 28; i++) {//存储小写字母的最小值
			if (cnt < st1[i]) {
				cnt = st1[i];
				x = i + 'a';

			}

		}

		printf("%c %d\n", x, cnt);




	}

	return 0;
}
posted @ 2023-07-18 16:13  EricFirst001  阅读(31)  评论(0)    收藏  举报