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 将字符串输入进去后,用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的更多相关文章
- UVa 1339 Ancient Cipher --- 水题
UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...
- UVa 1339,紫书P73,词频
题目链接:https://uva.onlinejudge.org/external/13/1339.pdf 紫书P73 解题报告: #include <stdio.h> #include ...
- uva 1339 Ancient Cipher
大意:读入两个字符串(都是大写字母),字符串中字母的顺序可以随便排列.现在希望有一种字母到字母的一一映射,从而使得一个字符串可以转换成另一个字符串(字母可以随便排列)有,输出YES:否,输出NO:ex ...
- 【例题 4-1 UVA - 1339】 Ancient Cipher
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 位置其实都没关系了. 只要每个字母都有对应的字母,它们的数量相同就可以了. 求出每种字母的数量. 排序之后. 肯定是要一一对应的. ...
- Ancient Cipher UVA - 1339
Ancient Roman empire had a strong government system with various departments, including a secret s ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
随机推荐
- CSS3实现文字抹开特效
CSS: .column-title { color: #9b9b9b; text-shadow: 1px 1px #d4d4d4;}.column-title:hover { color: #5a5 ...
- NYOJ题目457大小写互换
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsUAAAIUCAIAAAB9y8bFAAAgAElEQVR4nO3dPW7bTNsG0G8T7r0Qt/
- AJAX XML返回类型
例题 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...
- mysqlbinlog 查看日志时发生报错
[root@cs Downloads]# mysqlbinlog mysql-bin. ERROR: Error , event_type: ERROR: Could not read entry a ...
- EF – 8.多对多关联
5.6.10 <多对多关联(上)> 时长:9分57秒 难度:难 5.6.11<多对多关联(下)> 时长:8分50秒 难度:难 如果单独地把多对多关联的CRUD拿出来讲,确实比较 ...
- jQueryEasyUi验证
多重验证: { field : 'startPort', title : "起始端口", editor: "text", width : 50, edi ...
- MVC公开课 – 1.基础 (2013-3-15广州传智MVC公开课)
1.MVC设计模式 Model 是指 要处理的业务代码和数据操作代码 View 视图 主要是指的 跟用户打交道 并能够展示数据 Controller 看成是 Model和View的桥梁 优点: 1 ...
- Delphi字符串的基本操作与常用函数
参考:http://www.cnblogs.com/pchmonster/archive/2011/12/16/2290034.html 结合这个博客一起学习:http://www.cnblogs.c ...
- 【131031】<meta http-equiv=...> 的功能
1.定义语言 格式: 〈meta http-equiv=″Content-Type″ content=″text/html; charset=gb2312″〉 这是META最常见的用法,在制作网页时, ...
- GMap.Net开发之自定义Marker
上一篇文章介绍了如何在WinForm和WPF中使用GMap控件,这篇介绍下GMap中Marker的使用. 自定义Marker,可以理解为在地图上自定义图标(Custom Marker),先看看GMap ...