uva 1339

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

JWPUDJSTVP
VICTORIOUS
MAMA
ROME
HAHA
HEHE
AAA
AAA
NEERCISTHEBEST
SECRETMESSAGES

Sample Output

YES
NO
YES
YES
NO
时间: 2024-10-15 04:38:34

uva 1339的相关文章

UVa 1339 Ancient Cipher --- 水题

UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要,可以分别统计两个字符串中的各个字母出现的次数,得到两个cnt[26]数组, 又由于可以进行映射,则可以直接对两个数组进行排序后判断是否相等(相当于原来相等的值的两个地方做映射) /* UVa 1339 Ancient Cipher --- 水题 */ #include <cstdio> #incl

uva 1339 Ancient Cipher(字符串处理)

uva 1339 Ancient Cipher 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. T

UVa 1339 Ancient Cipher【排序】

/* 中文题目      古老的密码 中文翻译-大意  给你两个字符串,看你能不能将第一个字符变化位置(重排),变成和第二个字符串的26个字母一一对应. 解题思路:将两个字符串的各个字符的数量统计出来,如果各个字符串的数量都是一样的,那么就输出yes,否则输出no 难点详解:在统计每个字符出现的次数有点小难度 关键点:排序 解题人:lingnichong 解题时间:2014/08/26    00:36 解题体会:很好的一题 */ 1339 - Ancient Cipher Time limit

uva 1339 Ancient Cipher

大意:读入两个字符串(都是大写字母),字符串中字母的顺序可以随便排列.现在希望有一种字母到字母的一一映射,从而使得一个字符串可以转换成另一个字符串(字母可以随便排列)有,输出YES:否,输出NO:exp: 输入HAHAHEHE 输出YES 可以将A→E,或E→A: 关键在于,问题简化:因为不用考虑字母位置,所以可以分别统计两个字符串中不同字母出现次数,计入数组counts1和counts2.那么,怎么知道谁和谁对应呢?这里面有个隐含条件:如果A→B,那么A在1数组出现的次数和B在2数组中出现的次

UVa 1339 简单加密(encrypt)

背景:1Y,最简单的密码学! 思路:把每个字符串中每个字母的频数统计 出来,把频数相同的两个数映射就可,如果最后所有字母都有对应的映射,那么就是YES,permutation  cipher不需要管. 学习: 1.C语言stdlib.h里的qsort函数原型: void qsort(void * base,size_t num,size_t size,int (*comparator)(contst void *,const void * ); <pre name="code"

UAa 1339,紫书P73,词频

题目链接:https://uva.onlinejudge.org/external/13/1339.pdf 紫书P73 解题报告: #include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> using namespace std; int main() { //freopen("input.txt","r",stdin

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f