题解 UVA10008 【What's Cryptanalysis?】
很水的一道题!
注意:
-
全部转换成大写
-
只有大写字母才算
-
要排序,所以封装成类(结构体也可以)
代码:
#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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现