POJ2159 Ancient Cipher

    xiaoxiao2022-07-07  146

    POJ2159 http://poj.org/problem?id=2159

     

    题目大意:有点凯撒密码的意思,但是是向后移动一定的字符之后乱序排列形成密文。向后加密顺序相对好确定,但是还要错乱排序就显得很无解了。。。

    思路:按照密码学的统计规律结合题意,既然是同时加密,只要求各字符出现的频率保持一致即可。

    所以,我们只需统计两个字符串中字符出现的频率,进行对比即可。

     

    AC代码:

    #include <iostream> #include <stdio.h> #include <cstring> #include <algorithm> #include <cmath> #include <stack> #include <stdlib.h> #include <set> //#define DEBUG using namespace std; typedef long long ll; string a,b; int j[105],j2[105]; int main() { cin >> a; cin >> b; //memset(j,0, sizeof(j)); //memset(j2,0, sizeof(j2)); for(int i = 0;i < a.length();i++) { j[a[i]-'A']++; } for(int p = 0;p < b.length();p++) { j2[b[p]-'A']++; } sort(j,j+26); sort(j2,j2+26); for(int k = 0;k < 26; k++) { if(j[k]!=j2[k]) {cout << "NO\n"; return 0;} } cout << "YES\n"; return 0; }

     

    最新回复(0)