博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva1339 - Ancient Cipher
阅读量:7211 次
发布时间:2019-06-29

本文共 3248 字,大约阅读时间需要 10 分钟。

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 $ \langle$2, 1, 5, 4, 3, 7, 6, 10, 9, 8$ \rangle$ 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 题目大意:给你两个字符串,问你是否可以通过交换与映射后是两个字符串相同。 分析:水题,统计各个字符出现的次数后,排序在判断是否相等。
1 #include 
2 #include
3 #include
4 #include
5 #define maxlen 110 6 using namespace std; 7 int main() 8 { 9 char s1[maxlen],s2[maxlen];10 int a[30],b[30];11 while(scanf("%s%s",s1,s2)!=EOF)12 {13 int len;14 len=strlen(s1);15 memset(a,0,sizeof(a));16 memset(b,0,sizeof(b));17 for(int i=0; i
View Code

 

转载于:https://www.cnblogs.com/shuzy/p/3188247.html

你可能感兴趣的文章
不能忘记的一段日子
查看>>
驯服 Tiger: 并发集合
查看>>
优化MySQL的数据库性能的八种方法
查看>>
企业应用的Ant模组编译环境
查看>>
使用Maven管理Eclipse Java项目
查看>>
让Jacob从当前路径读取dll文件及相关打包方法
查看>>
我的友情链接
查看>>
Redis 集群方案
查看>>
Linux下查看软、硬raid信息的方法
查看>>
基本控件Password控件
查看>>
linux下命令集合
查看>>
[转载] 山楂树之恋——01-03
查看>>
PHP操作MongoDB学习笔记
查看>>
兼容性测试之VMware
查看>>
我的Git忽略文件
查看>>
Maven学习总结(二)——Maven项目构建过程练习
查看>>
MySQL性能调优my.cnf详解
查看>>
大型网站技术架构(二)架构模式
查看>>
计算机硬件基础与linux发展史
查看>>
如何在while和for中使用ssh
查看>>