文章

67

粉丝

66

获赞

67

访问

5.6k

头像
字母统计 题解:
P1292 上海交通大学机试题
发布于2024年4月28日 00:11
阅读数 89

#include <bits/stdc++.h>
using namespace std;

string str; 
int cnt[27];

int main()
{
	while(cin >> str)
	{
		memset(cnt, 0, sizeof cnt);
		for(int i = 0; i < str.size(); i ++)
			if(str[i] >= 'A' && str[i] <= 'Z')
				cnt[str[i] - 'A'] ++;
		
		for(int i = 0; i < 26; i ++)
			printf("%c:%d\n", char('A' + i), cnt[i]);
			
	}
	return 0;
} 

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发