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 将字符串输入进去后,用sort排序,再用两个数组将各个字母的个数存进数组里。再对比两个数组的数字是否完全一样。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = ; int main()
{
char str1[MAXN], str2[MAXN];
int a[], b[];
while(scanf("%s%*c", str1) != EOF)
{
scanf("%s%*c", str2); memset(a, , sizeof(a));
memset(b, , sizeof(b)); int len = strlen(str1);
sort(str1, str1+len);
sort(str2, str2+len); for(int i = ; i < len; ++i)
{
a[str1[i] - 'A']++;
b[str2[i] - 'A']++;
} sort(a, a+);
sort(b, b+); int mark = ;
for(int i = ; i < ; ++i)
{
if(a[i] == b[i])
{
mark++;
//printf("%d %d %d", a[i], b[i], mark);
}
}
//printf("%d\n", mark);
if(mark == )
printf("YES\n");
else
printf("NO\n");
}
return ;
}

uva 1339的更多相关文章

  1. UVa 1339 Ancient Cipher --- 水题

    UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...

  2. UVa 1339,紫书P73,词频

    题目链接:https://uva.onlinejudge.org/external/13/1339.pdf 紫书P73 解题报告: #include <stdio.h> #include ...

  3. uva 1339 Ancient Cipher

    大意:读入两个字符串(都是大写字母),字符串中字母的顺序可以随便排列.现在希望有一种字母到字母的一一映射,从而使得一个字符串可以转换成另一个字符串(字母可以随便排列)有,输出YES:否,输出NO:ex ...

  4. 【例题 4-1 UVA - 1339】 Ancient Cipher

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 位置其实都没关系了. 只要每个字母都有对应的字母,它们的数量相同就可以了. 求出每种字母的数量. 排序之后. 肯定是要一一对应的. ...

  5. Ancient Cipher UVA - 1339

      Ancient Roman empire had a strong government system with various departments, including a secret s ...

  6. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  7. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  8. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  9. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

随机推荐

  1. myeclipse 8.5 注册码

    刚才启动突然发现MyEclipse原来是收费的...汗一把,到弹出注册框我才知道.....老天啊我活的该有多窝囊.. 弹框很烦人,我一个穷书生既想继续学习又囊中羞涩无力购买,只好用盗版了(找个理由辩解 ...

  2. Mysql获取时间

    select now() 当前时间;   SELECT curdate() 当天日期; select date_sub(curdate(),interval 1 day) 前一天日期; select ...

  3. hdu1014

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 //hdu1014 0ms #include<stdio.h> #include&l ...

  4. 通过btn获取所在cell

    [cell.btn addTarget:self action:@selector(cellBtnClicked:event:) forControlEvents:UIControlEventTouc ...

  5. sql server 的cpu使用率过高的分析

    有哪些SQL语句会导致CPU过高? 1.编译和重编译 编译是 Sql Server 为指令生成执行计划的过程.Sql Server 要分析指令要做的事情,分析它所要访问的表格结构,也就是生成执行计划的 ...

  6. kvm 下运行的 WINWS7磁盘空间不足 增加磁盘 实战(这个有问题,还未解决)

    创建一个新硬盘: [root@NB vhost]# qemu-img create -f qcow2 add_win_desk.img 5G Formatting encryption=off clu ...

  7. 二叉树学习笔记之经典平衡二叉树(AVL树)

    二叉查找树(BSTree)中进行查找.插入和删除操作的时间复杂度都是O(h),其中h为树的高度.BST的高度直接影响到操作实现的性能,最坏情况下,二叉查找树会退化成一个单链表,比如插入的节点序列本身就 ...

  8. 不定义JQuery插件,不要说会JQuery 分类: JavaScript 2014-11-24 14:18 155人阅读 评论(0) 收藏

    一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写$("#"),$("."),写了几年就对别人说非常熟悉JQuery.我曾经也是这样的人 ...

  9. 杂物 git rebase

  10. 难得的中文ASP.NET 5/MVC 6入门教程

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:由于ASP.NET 5还未正式发布,即使是官方文档都还不完善,更不要说系统的中文文档了 ...