UVa1399.Ancient Cipher

2023-12-13 18:10
文章标签 ancient cipher uva1399

本文主要是介绍UVa1399.Ancient Cipher,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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

138559951339Ancient CipherAcceptedC++0.0122014-07-09 12:35:33

 


 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 $ \langle$2, 1, 5, 4, 3, 7, 6, 10, 9, 8$ \rangle$ 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

 解题思路:读了好长时间,没想到就是一道排序的水题。题目大意就是将一个字符串中的字符顺序改变后再不确定的一一对应是否能得到另外一个字符串。

 

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <cstdio>
 5 #include <cctype>
 6 #include <cmath>
 7 #include <algorithm>
 8 #include <numeric>
 9 using namespace std;
10 int main() {
11     string str1, str2;
12     int cnt1[26], cnt2[26];
13     while (cin >> str1 >> str2) {
14         memset(cnt1, 0, sizeof(cnt1));
15         memset(cnt2, 0, sizeof(cnt2));
16 
17         for(int i = 0; i < str1.size(); i++) {
18             cnt1[str1[i] - 'A'] ++;
19             cnt2[str2[i] - 'A'] ++;
20         }
21 
22         sort(cnt1, cnt1 + 26);
23         sort(cnt2, cnt2 + 26);
24 
25         bool flag = true;
26 
27         for(int i = 0 ; i < 26; i++) {
28             if(cnt1[i] != cnt2[i]) {
29                 flag = false;
30                 break;
31             }
32         }
33 
34         if(flag) cout << "YES" << endl;
35         else cout << "NO" << endl;
36 
37     }
38     return 0;
39 }

 

 

 

转载于:https://www.cnblogs.com/Destiny-Gem/p/3834531.html

这篇关于UVa1399.Ancient Cipher的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/489434

相关文章

第八届湘潭大学程序设计比赛 Problem C Cipher Lock

Cipher Lock Accepted : 33 Submit : 130Time Limit : 2500 MS Memory Limit : 65536 KB  题目描述 守护着神秘宝藏One Piece的是一把非常神秘的密码锁,这个密码锁有n排滚轮,每个滚轮有m个格子,刻着0,1两种数字。作为一把神秘的密码锁,开锁的方式却非常的简单,只要向左或向右转动滚轮使某一列的数字全

Codeforces 1C. Ancient Berland Circus(计算几何:正多边形性质+高精度)

给出三个点的坐标,输出含这三个点的最小正多边形面积 感觉这个题太牛逼了。。。 做的我元气大伤,昨晚看的题,一直没有思路 就去找了道类似的计算几何题Uva12300来做,做得还是挺顺手的 后来意识到了正多边形的一个性质:正n边形中一条边对应的圆心角为2×PI/n 以这里为突破口,先找出n的值,进而再求解 但有一个问题就是给定的点不一定相邻 也就是说两个点与圆心所对应的夹角有可能是多条边

OC的DES加密,使与java的Cipher类用DES/CBC/PKCS5Padding方式的加密结果相同

问题说明: 最近用到DES加密,并且要与java的Cipher类加密的结果保持一致。没研究过java的Cliper,但工作中Cipher根据DES/CBC/PKCS5Padding加密方式生成了一个字符串。比较后发现,此字符串与将OC加密生成的NSData直接用字符串格式化([NSString stringWithFormat:@"%@",data])相同。所以就先这么用了。 代码如下:

JS:Caesars Cipher(凯撒密码)

Caesars Cipher 凯撒密码 (让上帝的归上帝,凯撒的归凯撒) 下面我们来介绍风靡全球的凯撒密码Caesar cipher,又叫移位密码。 移位密码也就是密码中的字母会按照指定的数量来做移位。 一个常见的案例就是ROT13密码,字母会移位13个位置。由’A’ ↔ ‘N’, ‘B’ ↔ ‘O’,以此类推。 写一个ROT13函数,实现输入加密字符串,输出解密字符串。 所有的字母都

鸿蒙开发接口安全:【@system.cipher (加密算法)】

加密算法  说明: 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 导入模块 import cipher from '@system.cipher' cipher.rsa rsa(Object): void RSA 算法加解密。 系统能力:  SystemCapability.Security.Cipher 参数:

call to undefined function openssl cipher iv length() 报错 PHP7开启OpenSSL扩展失败 阿星小栈...

在安装laravel5.5后, 访问显示报错。 call to undefined function openssl cipher iv length() 经查为php7.1的OpenSSL扩展加载失败导致 恢复方法  检查http.conf   LoadModule ssl_module modules/mod_ssl.sophp.ini开启extension=php_open

ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value

新建用户: insert into mysql.user(user,host,password) values("test","%",password("test")); 出现以下提示: ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value 解决办法: 找到安装目录中的mysql.ini 修改 sq

POJ 2159 Ancient Cipher 杂题

题意:给定 str1, str2, 如果 str2 经过加密可以变成 str1。 输出YES,否则输出NO. 加密方式有两种,一种是改变字符,一种是调换顺序。 题解:这题还是耽搁了一会儿。一开始把题意理解错了,将substitution cipher (置换密码):当做按字典序偏移任意个位置。所以一直WR。 看了别人的解释: “substitution cipher (置换密码): S

CodeForces 611D:New Year and Ancient Prophecy DP + lcp

传送门 题目描述 给一个n位数,要求将该n位数拆分成若干数字,且需满足: 数字的顺序要严格递增数字都是正整数没有前导零求所有可能的方案数 分析 这道题写了好几天了2333 首先如何判断两个A和B谁大谁小 首先,如果A长度大于B长度,A大于B,反之亦然 如果AB长度相同,那么比较他俩的最长公共前缀,如果等于AB的长度,说明A等于B,如果不等于,那么就比较最强公共前缀的下一位即可 我们用数

例题6-13 古代象形符号(Ancient Messages,World Finals 2011,UVa 1103)

原题链接:https://vjudge.net/problem/UVA-1103 分类:图 备注:思维 前言:说实话我确实自己写不出,写下面代码的时候对一下uDebug,不过我没有看作者代码了(早就看了好几遍了),相当于我把作者的代码默写了一下,以后可能很多题都要这样吧,但是能默写出来说明我也是有好好理解这代码是怎么写出来的。我看了作者代码挺久才懂的,不知道下面讲的算不算清楚,对于尚未理解题目的人