文章

36

粉丝

0

获赞

4

访问

10.8k

头像
字母频率 题解:C
P1019 贵州大学机试题
发布于2024年3月24日 09:58
阅读数 253

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(){
	char s[1000],count[30];
	for(int i=0;i<30;i++){
		count[i]=0;
	}
	gets(s);
	for(int i=0;i<strlen(s);i++){
		s[i] = tolower(s[i]);
		count[(s[i]-97)]++;
	}
	int max,d;
	max = count[0];
	for(int i=1;i<30;i++){
		if(count[i]>max){
			max = count[i];
			d=i;
		}
	}
	printf("%c %d",d+97,max);
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发