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. python函数与函数式编程

    https://www.cnblogs.com/evablogs/p/6699515.html 在理解函数式编程之前,我还是对函数的调用,参数传递以及函数的嵌套调用一头雾水,还是花了点时间整理了写思绪 ...

  2. Mac Git 安装和配置

    一.git下载与安装 点击Git,然后选择下载安装包 git --version,终端输入该命令, 如输出版本号,则说明安装成功. git version 2.20.1 二.git基本配置 通过下面这 ...

  3. ASP.NET学习笔记 —— 一般处理程序之图片上传

    简单图片上传功能目标:实现从本地磁盘读取图片文件,展示到浏览器页面.步骤:(1). 首先创建一个用于上传图片的HTML模板,命名为ImageUpload.html: <!DOCTYPE html ...

  4. serialize()与serializeArray()

    1.了解serialize()与serializeArray() serialize()序列化表单元素,用于ajax请求, serializeArray()序列化表单元素,类似于serialize,但 ...

  5. ubuntu18.04从零开始配置环境(jdk+tomcat+idea)到使用idea开发web应用和servlet

    昨天吃了亏,搞了一下午才把环境配置好,故此将整个过程记录一下以防日后需要. 注意:因为我的博客模块的原因,所以我把图片压缩了一些,如果有看不清的, 可以  右键图片->在新标签页打开图片 目录: ...

  6. LinkedList与Queue

    https://blog.csdn.net/u013087513/article/details/52218725

  7. [认证授权] 4.OIDC(OpenId Connect)身份认证(核心部分)

    1 什么是OIDC? 看一下官方的介绍(http://openid.net/connect/): OpenID Connect 1.0 is a simple identity layer on to ...

  8. 在Winform开发中使用Grid++报表

    之前一直使用各种报表工具,如RDLC.DevExpress套件的XtraReport报表,在之前一些随笔也有介绍,最近接触锐浪的Grid++报表,做了一些测试例子和辅助类来处理报表内容,觉得还是很不错 ...

  9. iOS 友盟错误分析-2019

    友盟的错误分析越来越人性化了 前提集成了友盟统计,并打包的时候保留了.dSYM文件 先看看效果 可以看到bug显而易见的被发现了!那个文件夹,那一行代码 那么怎么才能这样呢 首先加入符号表,就是.dS ...

  10. C语言之输出空心棱形图案

    #include<stdio.h> #include<stdlib.h> void main() { int n,j,i; /*i为行数,j为每行中的项数*/ printf(& ...