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 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

Code

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#define MAX 1005
using namespace std;
char s1[MAX],s2[MAX];
int cnt1[26],cnt2[26];
int cmp(const void* a,const void* b){
return *(int*)a - *(int*)b;
}
int main()
{
while(~scanf("%s %s",s1,s2)){
int len1 = strlen(s1),len2 = strlen(s2);
for(int i = 0;i < len1;i ++) ++cnt1[s1[i]-'A'];
for(int j = 0;j < len2;j ++) ++cnt2[s2[j]-'A'];
qsort(cnt1,26,sizeof(int),cmp);
qsort(cnt2,26,sizeof(int),cmp);
int ok = 1;
for(int i = 0;i < 26;i ++)
if(cnt1[i]!=cnt2[i]) { ok = 0; break; }
if(ok) printf("YES\n");
else printf("NO\n");
memset(cnt1,0,sizeof(cnt1)); memset(cnt2,0,sizeof(cnt2));
}
return 0;
}

[算法竞赛入门经典]Ancient Cipher, NEERC 2004,UVa1339的更多相关文章

  1. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...

  2. [刷题]算法竞赛入门经典 3-12/UVa11809

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 题目:算法竞赛入门经典 3-4/UVa11809:Floating-Point Numbers 代码: //UVa11 ...

  3. [刷题]算法竞赛入门经典 3-10/UVa1587 3-11/UVa1588

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 题目:算法竞赛入门经典 3-10/UVa1587:Box 代码: //UVa1587 - Box #include&l ...

  4. [刷题]算法竞赛入门经典 3-7/UVa1368 3-8/UVa202 3-9/UVa10340

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 都是<算法竞赛入门经典(第二版)>的题目,标题上没写(第二版) 题目:算法竞赛入门经典 3-7/UVa13 ...

  5. [刷题]算法竞赛入门经典 3-4/UVa455 3-5/UVa227 3-6/UVa232

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 题目:算法竞赛入门经典 3-4/UVa455:Periodic Strings 代码: //UVa455 #inclu ...

  6. [刷题]算法竞赛入门经典 3-1/UVa1585 3-2/UVa1586 3-3/UVa1225

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO(我也是在网上找到的pdf,但不记得是从哪里搜刮到的了,就重新上传了一遍) PS:第一次写博客分享我的代码,不知道我对c ...

  7. 算法竞赛入门经典训练指南——UVA 11300 preading the Wealth

    A Communist regime is trying to redistribute wealth in a village. They have have decided to sit ever ...

  8. 算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

  9. 算法竞赛入门经典 LA 4329(树状数组)

    题意: 一排有着不同能力值的人比赛,规定裁判的序号只能在两人之间,而且技能值也只能在两人之间 问题: <算法竞赛入门经典-训练指南>的分析: 上代码: #include<iostre ...

随机推荐

  1. 把流的形式转化为Base64

    public class Test2 { public static String get() throws IOException { InputStream resourceAsStream = ...

  2. vue兄弟之间传值 bus中央事件总线

    创建一个eventVue.js文件 import Vue from 'vue' export default new Vue 父 <template> <div> <di ...

  3. MySQL二进预编译制安装

    +++++++++++++++++++++++++++++++++++++++++++标题:MySQL二进预编译制安装时间:2019年2月25日内容:MySQL二进制预编译安装重点:MySQL二进制预 ...

  4. Docker 核心技术之容器与镜像

    Docker容器与镜像的关系 容器提交 – docker commit docker commit -h 作用: 根据容器生成一个新的镜像 命令格式: docker commit [OPTIONS] ...

  5. c#使用资源文件完成国际化

    路径结构如下 namespace UnitTestProject1 { [TestClass] public class UnitTest1 { [TestMethod] public void Te ...

  6. Linux下Nginx配置阿里云 SSL证书实现HTTPS访问

    这篇文章主要介绍了nginx配置ssl证书实现https访问的示例 1.服务器系统:Centos 2. 阿里云申请SSL证书 选择“免费版DV SSL”,点击立即购买: 下载证书 列表中找到已签发的证 ...

  7. Kafka简介及使用PHP处理Kafka消息

    Kafka简介及使用PHP处理Kafka消息 Kafka 是一种高吞吐的分布式消息系统,能够替代传统的消息队列用于解耦合数据处理,缓存未处理消息等,同时具有更高的吞吐率,支持分区.多副本.冗余,因此被 ...

  8. Linux 下安装idea,提示svn版本太低问题

    在 RedHat 6.5 虚拟机上装了 Idea 2017, 将项目代码从 Windows 共享到虚拟机中,然后 Idea 提示 svn 版本太旧, 上网查资料说 Idea 2018 不支持1.7以下 ...

  9. 浅析 Scala 构造器

    2019-04-15 关键字:Scala 主构造器.Scala 辅助构造器.Scala 构造器的区别 本篇文章系笔者根据当前所掌握知识对 Scala 构造器的一些心得总结,不保证文章所述内容的绝对.完 ...

  10. Nginx从入门到实践(二)

    静态资源web服务 静态资源类型 CDN CDN的基本原理是广泛采用各种缓存服务器,将这些缓存服务器分布到用户访问相对集中的地区或网络中,在用户访问网站时,利用全局负载技术将用户的访问指向距离最近的工 ...