题解 UVA10008 【What's Cryptanalysis?】

很水的一道题!

注意:

  1. 全部转换成大写

  2. 只有大写字母才算

  3. 要排序,所以封装成类(结构体也可以)

代码:

#include <iostream>
#include <cctype>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;

class Node
{
public:
	int f, x;
	Node();
};

Node::Node()
{
	x = f = 0;
}

inline bool cmp(const Node& x, const Node& y)
{
	return (x.x == y.x ? x.f < y.f : x.x > y.x);
}

Node a[30];

int main()
{
	int n, cur = 0;
	cin >> n;
	getchar();
	for (register int i = 1; i <= n; i++)
	{
		string s;
		getline(cin, s);
		int len = s.length() - 1;
		transform(s.begin(), s.end(), s.begin(), ::toupper);
		for (register int j = 0; j <= len; j++)
		{
			if (s[j] >= 'A' && s[j] <= 'Z')
			{
				a[s[j] - 'A' + 1].x++;
				a[s[j] - 'A' + 1].f = int(s[j]);
			}
		}
	}
	sort(a + 1, a + 30, cmp);
	for (register int i = 1; i <= 26; i++)
	{
		if (a[i].x == 0 || a[i].f == 0)
		{
			continue;
		}
		else
		{
			cout << char(a[i].f) << " " << a[i].x << endl;
		}
	}
	//system("pause");
	return 0;
}
posted @   HappyBobb  阅读(2)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示