2159 -- Ancient Cipher
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 36074 | Accepted: 11765 |
Description
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
The lengths of both lines of the input are equal and do not exceed 100.
Output
Sample Input
JWPUDJSTVP
VICTORIOUS
Sample Output
YES
Source
题目大意:
古罗马帝王的保密服务部门的保密方法是替换和重新排列。
替换方法是将出现的字符替换成其他的字符。如将'A'替换成'Z',将'Z'替换成'A'。
排列方法是改变原来单词中字母的顺序。例如将顺序变为<2,1,5,4,3,7,6,10,9,8>。应用到字符串
"VICTORIOUS"上,则可以得到"IVOTCIRSUO"。
单用一种解密方法是不安全的,只有将两种方法结合起来才安全。那么问题来了:给你一个原文
字符串和加密字符串,问是否能通过这两种加密方法结合,从而由原文信息得到加密信息。如果
能则输出"YES",否则输出"NO"。
思路:
其实这道题没那么复杂,只要用两个数组分别存下两个字符串中各个字母的个数,排序一下,比较
字母个数是不是都相等就可以了,如果不是全相等,则说明不能从原文信息得到加密信息。如果全
相等,则一定有方法从原文信息得到加密信息。
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<map>
using namespace std;
int main()
{
map<char,int> First,Second;
char c = getchar();
while(c!='\n')
{
First[c]++;
c = getchar();
}
c = getchar();
while(c!='\n')
{
Second[c]++;
c = getchar();
}
map<char,int>::iterator FIter = First.begin();
for(;FIter!=First.end();)
{
int temp = ;
map<char,int>::iterator SIter = Second.begin();
for(;SIter!=Second.end();SIter++)
{
if(FIter->second == SIter->second)
{
char c1,c2;
c1 = FIter->first;c2 = SIter->first;
FIter++;SIter = Second.begin();
First.erase(c1);
Second.erase(c2);
temp = ;
break;
}
}
if(!temp)
FIter++;
}
//如果两个map不为空
if(First.size()||Second.size())
{
cout<<"NO"<<endl;
}else{
cout<<"YES"<<endl;
}
First.clear();
Second.clear(); return ;
}
2159 -- Ancient Cipher的更多相关文章
- Poj 2159 / OpenJudge 2159 Ancient Cipher
1.链接地址: http://poj.org/problem?id=2159 http://bailian.openjudge.cn/practice/2159 2.题目: Ancient Ciphe ...
- POJ 2159 Ancient Cipher 难度:0
题目链接:http://poj.org/problem?id=2159 #include <cstring> #include <cstdio> #include <cc ...
- POJ 2159 Ancient Cipher
题意:被题意杀了……orz……那个替换根本就不是ASCII码加几……就是随机的换成另一个字符…… 解法:只要统计每个字母的出现次数,然后把数组排序看相不相同就行了…… 代码: #include< ...
- POJ2159 ancient cipher - 思维题
2017-08-31 20:11:39 writer:pprp 一开始说好这个是个水题,就按照水题的想法来看,唉~ 最后还是懵逼了,感觉太复杂了,一开始想要排序两串字符,然后移动之类的,但是看了看 好 ...
- poj 2159 D - Ancient Cipher 文件加密
Ancient Cipher Description Ancient Roman empire had a strong government system with various departme ...
- uva--1339 - Ancient Cipher(模拟水体系列)
1339 - Ancient Cipher Ancient Roman empire had a strong government system with various departments, ...
- 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& ...
- Ancient Cipher UVa1339
这题就真的想刘汝佳说的那样,真的需要想象力,一开始还不明白一一映射是什么意思,到底是有顺序的映射?还是没顺序的映射? 答案是没顺序的映射,只要与26个字母一一映射就行 下面给出代码 //Uva1339 ...
随机推荐
- 17.SpringMVC核心技术-拦截器
SpringMVC 中的 Interceptor 拦截器是非常重要和相当有用的,它的主要作用是拦截指定 的用户请求, 并进行相应的预处理与后处理.其拦截的时间点在“处理器映射器根据用户提 交的请求映射 ...
- vscode go开发主要插件
• Colorization 代码着彩色 • Completion Lists 代码自动完成(使用gocode) • Snippets 代码片段 • Quick Info 快速提示信息(使用godef ...
- Javascript节点选择
jQuery.parent(expr) 找父亲节点,可以传入expr进行过滤,比如$("span").parent()或者$("span").parent(&q ...
- Vue介绍:vue导读2
一.实例中的成员 二.高级指令 三.组件初识 一.实例中的成员 # 计算computed <!DOCTYPE html> <html> <head> <met ...
- C 字符串几点
1.字符串结尾必须为“\0” 2.多种处理函数在<string.h> 3.常用字符串处理函数: 1.strlen 求字符串长度(\0不算在内) 2.strcpy(a,b) 将b复制到a中 ...
- 启动Tomcat报错:A child container failed during start
在之前的工作和学习当中,有碰到过很多未知的,在当时看来十分令人疑惑的问题.当时的解决手段简单粗暴,就是直接百度,搜到对应的解决方案,直接抄过来试试,不行再换,直到问题消失,程序可以正常跑了,立马就不管 ...
- python+Appium自动化:MultiAction多点触控
MultiAction MultiAction 是多点触控的类,常用于模拟用户多点操作. 主要包含这add()还有perform()两个方法,模拟多点触控,需要导入TouchAction还有Multi ...
- IDEA中配置Jetty Server
首先去 Eclipse官网下载Jetty jar包 鼠标移到Jetty上时 点击 Git it (得到它) 点击 .zip等待下载完成 然后 解压出来 接下就让我们 开始 使用IDEA了(创建一个We ...
- excel操作之poi-ooxml
目前市场上流行的对于excel处理的框架大致有两种:poi和jxl.对于这两种框架,我们可以做一个简单的对比: 1 开发团队:poi是Apache旗下的一个开源项目,由Apache官方维护,jxl ...
- oracle汉字排序
oracle在9i之前是对汉字的排序是按照二进制编码进行排序的,很不适合我们的国情,在oracle9i之后,汉字的排序方式有了以下三种方式: 1.使用拼音排序 NLS_SORT=SC ...