Ancient Cipher
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 36074   Accepted: 11765

Description

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 contains 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 are equal and do not exceed 100.

Output

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

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的更多相关文章

  1. Poj 2159 / OpenJudge 2159 Ancient Cipher

    1.链接地址: http://poj.org/problem?id=2159 http://bailian.openjudge.cn/practice/2159 2.题目: Ancient Ciphe ...

  2. POJ 2159 Ancient Cipher 难度:0

    题目链接:http://poj.org/problem?id=2159 #include <cstring> #include <cstdio> #include <cc ...

  3. POJ 2159 Ancient Cipher

    题意:被题意杀了……orz……那个替换根本就不是ASCII码加几……就是随机的换成另一个字符…… 解法:只要统计每个字母的出现次数,然后把数组排序看相不相同就行了…… 代码: #include< ...

  4. POJ2159 ancient cipher - 思维题

    2017-08-31 20:11:39 writer:pprp 一开始说好这个是个水题,就按照水题的想法来看,唉~ 最后还是懵逼了,感觉太复杂了,一开始想要排序两串字符,然后移动之类的,但是看了看 好 ...

  5. poj 2159 D - Ancient Cipher 文件加密

    Ancient Cipher Description Ancient Roman empire had a strong government system with various departme ...

  6. uva--1339 - Ancient Cipher(模拟水体系列)

    1339 - Ancient Cipher Ancient Roman empire had a strong government system with various departments, ...

  7. UVa 1339 Ancient Cipher --- 水题

    UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...

  8. UVa1399.Ancient Cipher

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. Ancient Cipher UVa1339

    这题就真的想刘汝佳说的那样,真的需要想象力,一开始还不明白一一映射是什么意思,到底是有顺序的映射?还是没顺序的映射? 答案是没顺序的映射,只要与26个字母一一映射就行 下面给出代码 //Uva1339 ...

随机推荐

  1. cookie 和session的关联关系

    session 1.1 数据存储,存服务器端, 浏览器解决http无状态问题的一种解决方案 登录,同一客户端访问服务端的时候,服务端都知道是这一个客户端 cookie 2.1 数据存储 , 存客户端 ...

  2. TF版网络模型搭建常用代码备忘

    本文主要介绍如何搭建一个网络并训练 最近,我在写代码时经常碰到这样的情况,明明记得代码应该怎么写,在写出来的代码调试时,总是有些小错误.原因不是接口参数个数不对,就是位置不对.为了节约上网查找时间,现 ...

  3. sudo身份切换

    sudo更改身份: 我们知道,使用 su 命令可以让普通用户切换到 root 身份去执行某些特权命令,但存在一些问题,比如说:仅仅为了一个特权操作就直接赋予普通用户控制系统的完整权限: 当多人使用同一 ...

  4. ContextMenu菜单创建 上下文菜单的基本认识q

    MainActivity.class public class MainActivity extends AppCompatActivity { @Override protected void on ...

  5. Centos7 docker、harbor 安装配置

    Docker 安装 wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo wget ...

  6. rdb和aof二种持久化方式对比(Redis)

    我们已经知道对于一个企业级的redis架构来说,持久化是不可减少的 企业级redis集群架构:海量数据.高并发.高可用 持久化主要是做灾难恢复,数据恢复,也可以归类到高可用的一个环节里面去 比如你re ...

  7. 说一下 HashSet 的实现原理?(未完成)

    说一下 HashSet 的实现原理?(未完成)

  8. Circular view path [mydemo]: would dispatch back to the current handler URL [/mydemo] again. Check your ViewResolver setup!

    简单创建一个springboot工程 pom.xml <?xml version="1.0" encoding="UTF-8"?><proje ...

  9. Rasterize order group

    增加shade 这里的并行 可以让更多 ...并行只在write那里wait 语法 struct I {float a [[raster_order_group(0)]];};

  10. struts2之多文件上传与拦截器(8)

    前台jsp <s:form action="uploadAction" enctype="multipart/form-data" method=&quo ...