Ancient Cipher 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
HINT
这道题目的映射是指的一个字母可以映射对应一个字母。映射的方式也不一定是按照一定的规律的。因此,只需要看看每一个字符串出现的次数是不是一样的就可以,要看是不是一样的就用到了排序算法,这里使用的是快排函数。
Accepted
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int cmp(const void* a, const void* b)
{
	return *(int*)a - *(int*)b;
}
int main()
{
	char arr[105];
	char arr1[105];
	while (scanf("%s", arr) != EOF && scanf("%s", arr1) != EOF)
	{
		int a[30] = { 0 };
		int b[30] = { 0 };
		for (int i = 0;i < strlen(arr); i++)
			a[arr[i] - 'A']++;
		for (int i = 0;i < strlen(arr1);i++)
			b[arr1[i] - 'A']++;
		qsort(a, 30, sizeof(int), cmp);
		qsort(b, 30, sizeof(int), cmp);
		int flag = 0;
		for(int i=0;i<30;i++)
			if(a[i]!=b[i])
			{
				flag = 1;
				break;
			}
		if (flag)printf("NO\n");
		else printf("YES\n");
	}
}
												
											Ancient Cipher UVA - 1339的更多相关文章
- UVa 1339 Ancient Cipher --- 水题
		
UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...
 - UVa1399.Ancient Cipher
		
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
 - uva--1339 - Ancient Cipher(模拟水体系列)
		
1339 - Ancient Cipher Ancient Roman empire had a strong government system with various departments, ...
 - Poj 2159 / OpenJudge 2159 Ancient Cipher
		
1.链接地址: http://poj.org/problem?id=2159 http://bailian.openjudge.cn/practice/2159 2.题目: Ancient Ciphe ...
 - Ancient Cipher UVa1339
		
这题就真的想刘汝佳说的那样,真的需要想象力,一开始还不明白一一映射是什么意思,到底是有顺序的映射?还是没顺序的映射? 答案是没顺序的映射,只要与26个字母一一映射就行 下面给出代码 //Uva1339 ...
 - poj 2159 D - Ancient Cipher 文件加密
		
Ancient Cipher Description Ancient Roman empire had a strong government system with various departme ...
 - POJ2159 Ancient Cipher
		
POJ2159 Ancient Cipher Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 38430 Accepted ...
 - POJ2159 ancient cipher - 思维题
		
2017-08-31 20:11:39 writer:pprp 一开始说好这个是个水题,就按照水题的想法来看,唉~ 最后还是懵逼了,感觉太复杂了,一开始想要排序两串字符,然后移动之类的,但是看了看 好 ...
 - 2159 -- Ancient Cipher
		
Ancient Cipher Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 36074 Accepted: 11765 ...
 
随机推荐
- 1107 Social Clusters——PAT甲级真题
			
1107 Social Clusters When register on a social network, you are always asked to specify your hobbies ...
 - 基于SaaS平台的iHRM项目的前端项目介绍
			
1.下载安装node.js 访问https://nodejs.org/en/,然后下载安装即可 2. 查看是否安装成功 打开cmd命令行,输入node -v 如果出现对应的版本号,即为安装成功 3.从 ...
 - 02.从0实现一个JVM语言之词法分析器-Lexer-03月02日更新
			
从0实现JVM语言之词法分析器-Lexer 本次有较大幅度更新, 老读者如果对前面的一些bug, 错误有疑问可以复盘或者留言. 源码github仓库, 如果这个系列文章对你有帮助, 希望获得你的一个s ...
 - MySql-Day-01
			
MySql 能够理解数据库的概念 能够安装MySQL数据库 能够启动,关闭及登录MySQL 能够使用SQL语句操作数据库 能够使用SQL语句操作表结构 能够使用SQL语句进行数据的添加修改和删除的操作 ...
 - 05.从0实现一个JVM语言之目标平台代码生成-CodeGenerator
			
从0实现JVM语言之目标平台代码生成-CodeGenerator 源码github仓库, 如果这个系列文章对你有帮助, 希望获得你的一个star 本节相关代码生成package地址 阶段性的告别 非常 ...
 - Java 面向对象 01
			
面向对象·一级 面向对象思想概述 * A:面向过程思想概述 * 第一步 * 第二步 * B:面向对象思想概述 * 找对象(第一步,第二步) * C:举例 * 买煎饼果子 ...
 - FreeBSD 入门 哲学与玄学
			
『哲学与玄学』 FreeBSD 是一种 UNIX 哲学(如模块化,一切皆文件等,见< UNIX 编程艺术>❩的发展,也是学院派的代表作品.她是一套工具集,她存在目的是为了让人们更好的生活. ...
 - springboot注解之@Import  @Conditional  @ImportResource  @ConfigurationProperties  @EnableConfigurationProperties
			
1.包结构 2.主程序类 1 @SpringBootApplication(scanBasePackages={"com.atguigu"}) 2 public class Mai ...
 - 基于Docker的MindSpore安装与使用基础介绍
			
技术背景 MindSpore是一款新一代AI开源计算框架,其特色在于:创新编程范式,AI科学家和工程师更易使用,便于开放式创新:该计算框架可满足终端.边缘计算.云全场景需求,能更好保护数据隐私:可开源 ...
 - js_笔记_8月7日记录_活动对象_作用域链_按值传递
			
活动对象:简单说就是这个函数的参数和显示声明的变量或函数. 函数内接受的参数实际是创建了一个局部变量:[形参名] = [传进来的值],js的函数传参只传值. 作用域链:执行流进入一个函数,会先创建出作 ...