POJ2159 Ancient Cipher
程序员文章站
2022-06-09 21:25:28
...
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;
}
推荐阅读
-
MySQL添加用户错误:ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value解决方法
-
Mapping Cipher
-
POJ 1107 W's Cipher题解
-
Des加密解密算法报错:Input length must be multiple of 8 when decrypting with padded cipher
-
AES加密/解密报错,Input length must be multiple of 16 when decrypting with padded cipher
-
Input length must be multiple of 8 when decrypting with padded cipher 错误
-
java对称加密报错:Input length must be multiple of 8 when decrypting with padded cipher
-
tomcat 8.0安装ssl证书,及centos7.2 的openssl升级到最新版本,及ERR_SSL_OBSOLETE_CIPHER错误解决...
-
springboot+mysql+ SSLHandshakeException: No appropriate protocol is disabled cipher+state 08S01
-
UVA1339 - Ancient Cipher(思维)