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 ...
随机推荐
- LLVM的RTTI特性
本文思路来源于http://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html,叙述有不同,望谅解,希望能从其他方面帮助大家了解C++语言的底层实现. 背景 在LLV ...
- svn中日志不展示解决方法记录
一,问题:点击svn查看日志时不显示.筛选时间显示为1970 1,猜想可能没有查看日志权限 2,查看linux 下svn版本库 confg 下三个配制文件 authz ,passwd ,svnserv ...
- Mac安装chromedriver和geckodriver
DY@MacBook-Pro bin$brew install chromedriver Error: No available formula with the name "chromed ...
- 数据库 Redis:Windows环境安装
1. 下载 Redis (1)前往 GitHub 下载:https://github.com/microsoftarchive/redis (2)点击 release : (3)选择好版本号后,下载文 ...
- Permission denied (publickey,gssapi-keyex,gssapi-with-mic)
当出现警告的时候,恭喜你,你已经离成功很近了. 远程主机这里设为slave2,用户为Hadoop. 本地主机设为slave1 以下都是在远程主机slave2上的配置,使得slave1可以免密码连接到s ...
- 【转】认证 (authentication) 和授权 (authorization) 的区别
以前一直分不清 authentication 和 authorization,其实很简单,举个例子来说: 你要登机,你需要出示你的身份证和机票,身份证是为了证明你张三确实是你张三,这就是 authen ...
- [Sping Boot] Build a REST CRUD API with Hibernate
pom.xml: <dependencies> <dependency> <groupId>org.springframework.boot</groupId ...
- Semantic 导航条
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- MFC 下拉框Combo Box
下拉框常用的事件是Change事件.属性常用:Data(英文;分隔),Sort(是否排序) // OnInitDialog()中 m_cbx.SetCurSel();//设置默认选项 //OnBnCl ...
- 微信小程序开发入门教程(四)---自己动手做个小程序
前面已将基础知识准备的差不多了,下面实际做一个小程序. 一.目标 用于上传照片和文字. 2个主要页面:我me,设置set 二.开始制作 1.打开微信开发者工具(我用的1.02.1907160 Wind ...