字符统计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;
}

本文作者:EricFirst001

本文链接:https://www.cnblogs.com/cuers/p/17563319.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   EricFirst001  阅读(9)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起