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. Spring cloud实战——服务提供者

    目录讲解: 一.服务提供者与服务消费者的概念 二.编写一个服务提供者的测试类(code) 1.1. 使用微服务构建的是分布式系统,微服务之间通过网络进行通信.我们使用微服务提供者与服务消费者来描述微服 ...

  2. MAVEN打包时没有将src/main/cache文件夹打到到WAR包中

    某项目中ehcache配置文件写在src/main/cache中,结果用maven打包时,得到的WAR包里面没有这个文件夹 因为maven打包时默认只打包src/main/java中的文件和src/m ...

  3. web开发:Bootstrap

    一.ajax请求 二.前台服务器概念 三.bs导读 四.bs引入 五.bs容器与响应式 一.ajax请求 - 后台 ```python# 通过flask框架搭建后台from flask import ...

  4. web开发:jquery初级

    一.JQ入门 二.引入JQ 三.页面加载 四.分析JQ源码流程 五.JQ操作 六.c菜单栏案例 一.JQ入门 what is jQuery ???1.jQuery是对原生JavaScript二次封装的 ...

  5. 关于pycharm database查看db.sqlites文件提示:Driver class 'org.sqlite.JDBC' not found

    系统重新安装后,启动pycharm存在各种问题,其中一个问题就是在Pycharm中的database里面不能查看sqlite数据库了: 经过一番查找终于找到了问题: 首先问题 是提示这样一个报错: 解 ...

  6. 区块链火爆,再不知道Golang就晚了

    Golang,也叫Go语言,是2009年刚刚被发发布的一门新语言. 区块链,是2019年我国提出的新战略. 一个不争的事实就是,大多数从事区块链开发的小伙伴都是用Golang,大多数招聘区块链技术工作 ...

  7. mongodb的安装与使用(二)之 增删改查与索引

    0.MongoDB数据库和集合创建与删除 MongoDB 创建数据库 语法: use DATABASE_NAME note:查看所有数据库使用show dbs 创建的空数据库 test并不在数据库的列 ...

  8. UVALive 6862——结论题&&水题

    题目 链接 题意:求满足$0 \leq x \leq y \leq z \leq m$且$x^j + y^j = z^j, \ j=2 \cdots n$的三元组的对数 分析 由费马大定理:整数$n ...

  9. vue-cropperjs 图片裁剪上传功能使用方法记录

    引入: 官网:https://www.npmjs.com/package/vue-cropperjs 控制台输入: npm install --save vue-cropperjs vue 项目中引入 ...

  10. JavaScript三元运算符

    ㈠条件运算符也叫做三元运算符 ⑴语法:条件表达式?语句1:语句2: ⑵执行的流程: ①条件运算符在执行时,首先对条件表达式进行求值 ▶如果该值为true,则执行语句1,并返回执行结果 ▶如果该值为fa ...