UVA 1339
来源:互联网 发布:网络舆论引导员工资单 编辑:程序博客网 时间:2024/06/11 03:07
Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents were sent between provinces and the capital in encrypted form to prevent eavesdropping. The most popular ciphers in those times were so called substitution cipher and permutation cipher. Substitution cipher changes all occurrences of each letter to some other letter. Substitutes for all letters must be different. For some letters substitute letter may coincide with the original letter. For example, applying substitution cipher that changes all letters from `A' to `Y' to the next ones in the alphabet, and changes `Z' to `A', to the message ``VICTORIOUS'' one gets the message ``WJDUPSJPVT''. Permutation cipher applies some permutation to the letters of the message. For example, applying the permutation 2, 1, 5, 4, 3, 7, 6, 10, 9, 8 to the message ``VICTORIOUS'' one gets the message ``IVOTCIRSUO''. It was quickly noticed that being applied separately, both substitution cipher and permutation cipher were rather weak. But when being combined, they were strong enough for those times. Thus, the most important messages were first encrypted using substitution cipher, and then the result was encrypted using permutation cipher. Encrypting the message ``VICTORIOUS'' with the combination of the ciphers described above one gets the message ``JWPUDJSTVP''. Archeologists have recently found the message engraved on a stone plate. At the first glance it seemed completely meaningless, so it was suggested that the message was encrypted with some substitution and permutation ciphers. They have conjectured the possible text of the original message that was encrypted, and now they want to check their conjecture. They need a computer program to do it, so you have to write one.
Input
Input file contains several test cases. Each of them consists of two lines. The first line contains the message engraved on the plate. Before encrypting, all spaces and punctuation marks were removed, so the encrypted message contains only capital letters of the English alphabet. The second line contains the original message that is conjectured to be encrypted in the message on the first line. It also contains only capital letters of the English alphabet. The lengths of both lines of the input file are equal and do not exceed 100.Output
For each test case, print one output line. Output `YES' if the message on the first line of the input file could be the result of encrypting the message on the second line, or `NO' in the other case.Sample Input
JWPUDJSTVPVICTORIOUSMAMAROMEHAHAHEHEAAAAAANEERCISTHEBESTSECRETMESSAGES
Sample Output
YESNOYESYESNO
挺水的一道题结果读错题了 , 囧TZ , 只要考虑字母出现的次数就可以了,不必在意字母是什么。
#include <cstdio>#include <cmath>#include <algorithm>#include <iostream>#include <cstring>#include <map>#include <string>#include <stack>#include <cctype>#include <vector>#include <queue>#include <set>using namespace std;const int MAXN = 500000 + 50;const int maxw = 100 + 20;const long long LLMAX = 0x7fffffffffffffffLL;const long long LLMIN = 0x8000000000000000LL;const int INF = 0x7fffffff;const int IMIN = 0x80000000;#define eps 1e10-8#define mod 1000000007typedef long long LL;const double PI = acos(-1.0);typedef double D;//#define Online_Judge#define outstars cout << "***********************" << endl;#define clr(a,b) memset(a,b,sizeof(a))#define clr(a,b) memset(a,b,sizeof(a))#define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++)#define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++)#define REP(i , x , n) for(int i = (x) ; i > (n) ; i--)#define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--)int a[26], b[26];char s1[120] , s2[120];int main(){ #ifdef Online_Judge freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif // Online_Judge while(gets(s1)&&gets(s2)) { clr(a , 0); clr(b , 0); int n = strlen(s1); int ok = 1; FOR(i ,0 , n) { a[s1[i] - 'A']++; b[s2[i] - 'A']++; } sort(a , a + 26); sort(b , b + 26);// FOR(i , 0 , 26)cout << a[i] ;// FOR(j , 0 , 26)cout << b[j] ; if(memcmp(a , b , sizeof(a)))ok = 0; puts(ok ? "YES" : "NO"); } return 0;}
- UVA 1339
- uva 1339
- UVa 1339
- UVa 1339
- UVA-1339
- UVa 1339
- UVa 1339
- UVA 1339
- UVA 1339
- UVA 1339
- UVa 1339
- uva 1339
- UVA Ancient Cipher UVA - 1339
- UVA 1339 - Ancient Cipher
- uva 1339 Ancient Cipher
- Uva - 1339 - Ancient Cipher
- UVA 1339 - Ancient Cipher
- UVA 1339 - Ancient Cipherguo
- 怎么使用JavaBean组件
- 树形查询中where的作用
- Ural 1141. RSA Attack 扩展欧几里得算法
- 最长上升子序列
- 实模式和保护模式
- UVA 1339
- Ministry
- Android组件的使用:Menu
- POJ-3498-March of the Penguins
- iOS简单加载一个网页
- 网站是否需要经常更新要看具体情况而定
- iOS 消息推送通知
- [Android]屏幕跳转
- 设计模式之单例模式(代码)