uva-1339Ancient 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. 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的更多相关文章
- UVA 306 Cipher
题意 :lucky cat里有翻译.英文也比较好懂. 很容易发现有周期然后就拍就好了 注意每组数据后边都有空行 包括最后一组.一开始以为最后一组没有空行.唉.. #include <map> ...
- UVa 1339 Ancient Cipher --- 水题
UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...
- Ancient Cipher UVA - 1339
Ancient Roman empire had a strong government system with various departments, including a secret s ...
- uva 1339 Ancient Cipher
大意:读入两个字符串(都是大写字母),字符串中字母的顺序可以随便排列.现在希望有一种字母到字母的一一映射,从而使得一个字符串可以转换成另一个字符串(字母可以随便排列)有,输出YES:否,输出NO:ex ...
- 【UVA 1586】Ancient Cipher
题 题意 给你一个只含CHON的有机物的化学式如C6H5OH求相对分子质量 分析 ... 代码 switch #include<cstdio> #include<cctype> ...
- UVa LA 3213 - Ancient Cipher 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- 【例题 4-1 UVA - 1339】 Ancient Cipher
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 位置其实都没关系了. 只要每个字母都有对应的字母,它们的数量相同就可以了. 求出每种字母的数量. 排序之后. 肯定是要一一对应的. ...
- UVa1399.Ancient Cipher
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- JAVA实现AES 解密报错Input length must be multiple of 16 when decrypting with padded cipher
加密代码 /**解密 * @param content 待解密内容 * @param password 解密密钥 * @return */ public static byte[] decrypt(b ...
- POJ1026 Cipher(置换的幂运算)
链接:http://poj.org/problem?id=1026 Cipher Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...
随机推荐
- 有关Java的优秀博客集锦
1. 在java编程中,多线程并发总有些疑惑:如为什么会产生并发?并发会有什么影响?java中提供了哪些处理并发的技术(机制) 关于并发产生的原因,我查了一些资料目前发现有两种原因:一,存在共享的资源 ...
- poj 3661 Running
题意:给你一个n,m,n表示有n分钟,每i分钟对应的是第i分钟能跑的距离,m代表最大疲劳度,每跑一分钟疲劳度+1,当疲劳度==m,必须休息,在任意时刻都可以选择休息,如果选择休息,那么必须休息到疲劳度 ...
- Android Tab -- 使用ViewPager、Fragment、FragmentPagerAdapter来实现
原文地址:http://blog.csdn.net/crazy1235/article/details/42678877 效果:滑动切换:点击标签切换. 代码:https://github.com/l ...
- oracle一点记录
查看数据库实例名(SERVICE_NAME): sql: select instance_name from v$instance; 如何知道oracle客户端是32位还是64的.windows下启动 ...
- 【翻译七】java-同步
Synchronization Threads communicate primarily by sharing access to fields and the objects reference ...
- Sexagenary Cycle(天干地支法表示农历年份)
Sexagenary Cycle Time Limit: 2 Seconds Memory Limit: 65536 KB 题目链接:zoj 4669 The Chinese sexagen ...
- MySQL5.6 on Windows 安装失败: String was not recognized as a valid DateTime
在Win7,32位上安装MySQL5.6.21时出现日期/时间格式错误, 如下图所示: 错误描述为: String was not recognized as a valid DateTime. 下面 ...
- 浅谈config文件的使用
一.缘起 最近做项目开始使用C#,因为以前一直使用的是C++,因此面向对象思想方面的知识还是比较全面的,反而是因没有经过完整.系统的.Net方面知识的系统学习,经常被一些在C#老鸟眼里几乎是常识的小知 ...
- 攻城狮在路上(伍)How tomcat works(四)Tomcat的默认连接器
在第4章中将通过剖析Tomcat4的默认连接器的代码,讨论需要什么来创建一个真实的Tomcat连接器. 注意:本章中提及的“默认连接器”是指Tomcat4的默认连接器.即使默认的连机器已经被 ...
- RFC(请求注解)--各种协议-标准
转自:http://blog.sina.com.cn/s/blog_65d6476a0101cj8n.html RFC(Request For Comments)-意即“请求注解”,包含了关于Inte ...