题解 造福后人
2024-08-25 17:50:53
发布于:广东
55阅读
0回复
0点赞
不知道这代码放洛谷为什么不对
没关系反正在这过了
这玩意就是纯解密
就是记录出现最多的字母,然后根据常识在英文中,E
出现的频率最高,所以就可以得到偏移量
#include <iostream>
#include <cstdio>
#include <cstring>
#include <memory.h>
using namespace std;
string a[100005];
int bucket[26], ct;
int main(){
string s, _start, _end;
while(getline(cin, _start), getline(cin, a[++ct]), getline(cin, _end)){
//memset(bucket, 0, sizeof(bucket));
if(_start == "ENDOFINPUT") break;
for(int i = 0; a[ct][i] != '\0'; i++){
if(isalpha(a[ct][i])) bucket[(a[ct][i] < 'a' ? a[ct][i] - 'A' : a[ct][i] - 'a')]++;
}
}
int mx = 0, idx = 0;
for(int i = 0; i < 26; i++){
if(mx < bucket[i]){
idx = i, mx = bucket[i];
}
}
int tmp = idx - 4;
for(int i = 1; i <= ct; i++){
for(int j = 0; a[i][j] != '\0'; j++){
if(isalpha(a[i][j])){
a[i][j] -= tmp;
if(a[i][j] < 'A') a[i][j] += 26;
if(a[i][j] > 'Z') a[i][j] -= 26;
}
}
cout << a[i];
if(i != ct) cout << endl;
}
}
这里空空如也
有帮助,赞一个