紫书例题-Ancient Cipher
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
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
using namespace std; int main()
{
int i;
char cnt1[],cnt2[];
int num1[]={},num2[]={};
while(cin>>cnt1>>cnt2){
int fla=;
memset(num1,,sizeof(num1));
memset(num2,,sizeof(num2)); for(i=;i<strlen(cnt1);i++){
num1[cnt1[i]-'A']++;
num2[cnt2[i]-'A']++;
}
sort(num1,num1+);
sort(num2,num2+);
for(i=;i<;i++){
if(num1[i]!=num2[i]){
fla=;
}
} if(fla) cout<<"NO"<<endl;
else
cout<<"YES"<<endl; }return ;
}
水题,统计每个字母出现的个数就好
紫书例题-Ancient Cipher的更多相关文章
- 紫书 例题 11-13 UVa 10735(混合图的欧拉回路)(最大流)
这道题写了两个多小时-- 首先讲一下怎么建模 我们的目的是让所有点的出度等于入度 那么我们可以把点分为两部分, 一部分出度大于入度, 一部分入度大于出度 那么显然, 按照书里的思路,将边方向后,就相当 ...
- 紫书 例题8-3 UVa 1152(中途相遇法)
这道题要逆向思维, 就是求出答案的一部分, 然后反过去去寻找答案存不存在. 其实很多其他题都用了这道题目的方法, 自己以前都没有发现, 这道题专门考这个方法.这个方法可以没有一直往下求, 可以省去很多 ...
- 紫书 例题8-12 UVa 12627 (找规律 + 递归)
紫书上有很明显的笔误, 公式写错了.g(k, i)的那个公式应该加上c(k-1)而不是c(k).如果加上c(k-1)那就是这一次 所有的红气球的数目, 肯定大于最下面i行的红气球数 我用的是f的公式, ...
- 紫书 例题8-4 UVa 11134(问题分解 + 贪心)
这道题目可以把问题分解, 因为x坐标和y坐标的答案之间没有联系, 所以可以单独求两个坐标的答案 我一开始想的是按照左区间从小到大, 相同的时候从右区间从小到大排序, 然后WA 去uDebug找了数据 ...
- 紫书 例题8-17 UVa 1609 (构造法)(详细注释)
这道题用构造法, 就是自己依据题目想出一种可以得到解的方法, 没有什么规律可言, 只能根据题目本身来思考. 这道题的构造法比较复杂, 不知道刘汝佳是怎么想出来的, 我想的话肯定想不到. 具体思路紫书上 ...
- 紫书 例题 9-5 UVa 12563 ( 01背包变形)
总的来说就是价值为1,时间因物品而变,同时注意要刚好取到的01背包 (1)时间方面.按照题意,每首歌的时间最多为t + w - 1,这里要注意. 同时记得最后要加入时间为678的一首歌曲 (2)这里因 ...
- UVA1339 - Ancient Cipher 【字符串+排序】【紫书例题4.1】
题意:给定两个字符串,你可以替换或者置换,替换是指可以将相同的字母替换为任意一个字母,而置换是指将字母替换为下一个,如A替换B,B替换为C,,,Z替换为A.你需要判断是否可以通过一系列操作使两个字符串 ...
- UVA489 - Hangman Judge【紫书例题4.2】
题意:就是给出一个字符串,让你去一个一个猜测,相同字母算一次,如果是之前猜过的也算错,如果你在错7次前猜对就算你赢,文章中是LRJ的例题代码. #include<stdio.h> #inc ...
- 紫书 例题 10-2 UVa 12169 (暴力枚举)
就是暴力枚举a, b然后和题目给的数据比较就ok了. 刘汝佳这道题的讲解有点迷,书上讲有x1和a可以算出x2, 但是很明显x2 = (a * x1 +b) 没有b怎么算x2?然后我就思考了很久,最后去 ...
随机推荐
- FlippingBook使用教程
FlippingBook是一款收费的图书翻页效果的flash播放器.在线预览地址:FlippingBook,破解版下载地址 备用下载地址 预览效果: 它的文件结构如下: 其中:css文件夹是一个简单的 ...
- C# 获得MP4时长
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q95-Q98)
Question 95 Your development team has asked you to help them determine the cause of an error in a ...
- Android布局优化策略
我们要知道布局是否合理,可以通过Hierarchy Viewer这个工具.打开Hierarchy Viewer(定位到tools/目录下,直接执行hierarchyviewer的命令,选定需要查看的P ...
- 请各位帮帮忙:Android LBS应用——CityExplorer (v1.0) 调研
Hello哇各位亲!! 请各位帮帮忙:Android LBS应用——CityExplorer(V1.0)调研 嗯,这个事情是这样的,要填一个调查问卷,但是问卷中部分问题是关于这个叫做CityExplo ...
- iOS开发之邓白氏编码申请流程
要申请企业证书,必须先申请邓白氏编码,在苹果网站有一个免费申请邓白氏编码的链接:https://developer.apple.com/program/enroll/dunsLookupForm.ac ...
- IOS 杂笔-1(为什么不继承类簇?)
答:首先,类簇是可以继承的,并不是不可以.例如,我们可以选择继承NSSting,但是此时你用你自己设定的类去调用NSSting的一些方法时,会存在无法实现的问题,这是为什么呢. 1.类簇里有很多私有的 ...
- ListView的监听器中OnItemClick各个参数的作用
方法的原型如下 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3){ } 后面有4个参 ...
- Maven基础使用
常用命令 mvn clean:清除maven的编译结果 mvn compile:编译 mvn package:编译.打包 mvn install:编译.打包.部署 –DskipTests:编译测试用例 ...
- Asp.net MVC验证哪些事(3)-- Remote验证及其改进(附源码)
表单中的输入项,有些是固定的,不变的验证规则,比如字符长度,必填等.但有些是动态的,比如注册用户名是否存在这样的检查,这个需要访问服务器后台才能解决.这篇文章将会介绍MVC中如何使用[RemoteAt ...