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 题目理解了半天,然后又去看别人的思路,还差得好远,
还有就是,memset()的用法忘记了,然后自己就胡乱写数组所占内存空间,结果。。。
#include <stdio.h>
#include <stdlib.h>
#include <string.h> ///学习了一下QuickSort,要好好努力
int AdjustArray(int s[], int l, int r)
{
int i = l, j = r;
int x = s[l];
while(i < j)
{
while(i < j && s[j] >= x)
j--;
if(i < j)
{
s[i] = s[j];
i++;
} while(i < j && s[i] < x)
i++;
if(i < j)
{
s[j] = s[i];
j--;
}
} s[i] = x;
return i;
}
void QuickSort(int a[], int l, int r)
{
if(l < r)
{
int i = AdjustArray(a, l, r);
QuickSort(a, l, i-);
QuickSort(a, i+, r);
}
} ///这是合并版,感觉人家讲的挺好 http://blog.csdn.net/morewindows/article/details/6684558
void quick_sort(int s[], int l, int r)
{
if(l < r)
{
int i = l, j = r, x = s[l];
while(i < j)
{
while(i < j && s[j] >= x)
j--;
if(i < j)
s[i++] = s[j]; while(i < j && s[i] < x)
i++;
if(i < j)
s[j--] = s[i];
}
s[i] = x;
quick_sort(s, l, i-);
quick_sort(s, i+, r);
}
}
int main()
{
char s1[], s2[];
int a[], b[];
while(scanf("%s%*c", s1) != EOF)
{
scanf("%s%*c", s2);
int len = strlen(s1);
memset(a, , sizeof(a));
memset(b, , sizeof(b)); int i = ;
for(i = ; i < len; ++i)
{
a[s1[i] - 'A']++;
b[s2[i] - 'A']++;
} quick_sort(a, , );
quick_sort(b, , ); int num = ;
for(i = ; i < ; ++i)
{
if(a[i] == b[i])
{
num++;
}
else
break;
} if(num == )
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return ;
}

uva-1339Ancient Cipher的更多相关文章

  1. UVA 306 Cipher

    题意 :lucky cat里有翻译.英文也比较好懂. 很容易发现有周期然后就拍就好了 注意每组数据后边都有空行 包括最后一组.一开始以为最后一组没有空行.唉.. #include <map> ...

  2. UVa 1339 Ancient Cipher --- 水题

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

  3. Ancient Cipher UVA - 1339

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

  4. uva 1339 Ancient Cipher

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

  5. 【UVA 1586】Ancient Cipher

    题 题意 给你一个只含CHON的有机物的化学式如C6H5OH求相对分子质量 分析 ... 代码 switch #include<cstdio> #include<cctype> ...

  6. UVa LA 3213 - Ancient Cipher 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

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

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

  8. UVa1399.Ancient Cipher

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. JAVA实现AES 解密报错Input length must be multiple of 16 when decrypting with padded cipher

    加密代码 /**解密 * @param content 待解密内容 * @param password 解密密钥 * @return */ public static byte[] decrypt(b ...

  10. POJ1026 Cipher(置换的幂运算)

    链接:http://poj.org/problem?id=1026 Cipher Time Limit: 1000MS   Memory Limit: 10000K Total Submissions ...

随机推荐

  1. oracle sqlplus存储过程控制台输出信息

    如果你是使用PL/sql工具,在command 窗口下执行set serveroutput on 然后exec sp;可以看到了或者在sqlplus 中执行上面的代码

  2. Mysql之mysqlbinlog使用

    mysqlbinlog用于BinLog的显示,备份和重做. 默认情况下,mysqlbinlog是以base-64编码的方式呈现的.如: mysqlbinlog  master_bin.000006   ...

  3. iPhone:4.7 5.5 4 3.5 对应的各个设备屏幕尺寸对应的像素及App上线信息

    Shared App Information You can access these properties from the App Details page in the App Informat ...

  4. 20145206《Java程序设计》实验五Java网络编程及安全

    20145206<Java程序设计>实验五 Java网络编程及安全 实验内容 1.掌握Socket程序的编写: 2.掌握密码技术的使用: 3.设计安全传输系统. 实验步骤 我和201451 ...

  5. set -x 跟踪脚本执行信息

    注意set -x其中"-"与"x"之间没有空格 [root@GitLab sh]# ./sx.sh heelo + a=heelo + echo heelo h ...

  6. 磁盘空间占满inode结点没用完 并删除了文件但是释放不了

    lsof  |grep delete lsof(list system open file )可显示系统打开的文件,以root身份运行. 很多时候文件正在被占用,即使删除了,也无法释放空间,只有停 了 ...

  7. rhel7初体验

    Redhat7界面明显比之前的版本华丽了不少,貌似Redhat对普通用户的使用也要进行普及 可以在安装的同时修改root密码和创建新用户

  8. sqlplus使用(一)

    一,sqlplus 环境变量 sqlplus的环境变量(来自SQL*Plus® User's Guide and Reference Release 11.2) Parameter or Variab ...

  9. SQL常见错误及处理方法

    1.情况:数据库引擎安装失败,报类似权限不足的错误 解决:可能由于计算机名和用户名相同导致,更改计算机名,卸载干净重装即可

  10. x264中I,P,B帧和PTS,DTS的关系

    转自:http://www.cppblog.com/tx7do/archive/2013/01/30/197633.html 基本概念: I frame :帧内编码帧 又称intra picture, ...