古代密码

这里写图片描述
这里写图片描述
好的,根据一贯尿性,博主是做错了的,还以为整体字母对应的是全部整体平移,结果是随便排,没有任何规律,那就尴尬了,其实这道题的大概意思就是能否找到一种神奇的对应规则,让原词对应到密码就行了,也就是说我们只需要统计各单词出现的次数,然后对次数排序之后,一个一个对比(这里的意思是说如果某个字母转换后变为了某个字母,这两个的出现次数应该是一样的对吧)。那就是这样了,下面是代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
char s1[105],s2[105];
int mi[30],yuan[30];
int main()
{
    cin>>s1>>s2;
    if(strlen(s1)!=strlen(s2)){
        cout<<"NO";
        return 0;
    }
    for(int i=0;i<strlen(s1);i++){
        mi[s1[i]-'A']++;
        yuan[s2[i]-'A']++;
    }
    sort(mi,mi+26);
    sort(yuan,yuan+26);
    int k;
    for(k=0;k<26;k++)
        if(mi[k]!=yuan[k]) break;
    if(k==26) cout<<"YES";
    else cout<<"NO";
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ghost_pig/article/details/79834492