1 条题解
-
1
Infinity_ LV 8 @ 8 个月前
实际上只要建立从 2个字母 到 1~676(26^2) 的双射函数,剩下的就好办了
我用的是f(a, b) = 26a+b (a,b∈N且1≤a,b≤26)
- 1
信息
- ID
- 1103
- 难度
- 8
- 分类
- (无)
- 标签
- 递交数
- 113
- 已通过
- 15
- 通过率
- 13%
- 上传者
实际上只要建立从 2个字母 到 1~676(26^2) 的双射函数,剩下的就好办了
我用的是f(a, b) = 26a+b (a,b∈N且1≤a,b≤26)
#include<iostream>
#include<cstring>
#include<ctype.h>
using namespace std;
int a[680];
string s;
int main(){
ios::sync_with_stdio(false);
memset(a, 0, sizeof(a));
getline(cin, s);
int len = s.size() - 1, Max = -1000000000;
for(int i = 0; i < len; i++){
if(isalpha(s[i]) && isalpha(s[i+1])){
a[26*(tolower(s[i])-97)+(tolower(s[i+1])-96)]++;
}
}
for(int i = 1; i <= 676; i++){
if(a[i] > Max)Max = a[i];
}
for(int i = 1; i <= 676; i++){
if(a[i] == Max){
if(i % 26)cout << char(i/26+97) << char(i%26+96) << ' ';
else cout << char(i/26+96) << "z ";
}
}
return 0;
}