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 题目理解了半天,然后又去看别人的思路,还差得好远,
还有就是,memset()的用法忘记了,然后自己就胡乱写数组所占内存空间,结果。。。
#include <stdio.h>
#include <stdlib.h>
#include <string.h> ///学习了一下QuickSort,要好好努力
int AdjustArray(int s[], int l, int r)
{
int i = l, j = r;
int x = s[l];
while(i < j)
{
while(i < j && s[j] >= x)
j--;
if(i < j)
{
s[i] = s[j];
i++;
} while(i < j && s[i] < x)
i++;
if(i < j)
{
s[j] = s[i];
j--;
}
} s[i] = x;
return i;
}
void QuickSort(int a[], int l, int r)
{
if(l < r)
{
int i = AdjustArray(a, l, r);
QuickSort(a, l, i-);
QuickSort(a, i+, r);
}
} ///这是合并版,感觉人家讲的挺好 http://blog.csdn.net/morewindows/article/details/6684558
void quick_sort(int s[], int l, int r)
{
if(l < r)
{
int i = l, j = r, x = s[l];
while(i < j)
{
while(i < j && s[j] >= x)
j--;
if(i < j)
s[i++] = s[j]; while(i < j && s[i] < x)
i++;
if(i < j)
s[j--] = s[i];
}
s[i] = x;
quick_sort(s, l, i-);
quick_sort(s, i+, r);
}
}
int main()
{
char s1[], s2[];
int a[], b[];
while(scanf("%s%*c", s1) != EOF)
{
scanf("%s%*c", s2);
int len = strlen(s1);
memset(a, , sizeof(a));
memset(b, , sizeof(b)); int i = ;
for(i = ; i < len; ++i)
{
a[s1[i] - 'A']++;
b[s2[i] - 'A']++;
} quick_sort(a, , );
quick_sort(b, , ); int num = ;
for(i = ; i < ; ++i)
{
if(a[i] == b[i])
{
num++;
}
else
break;
} if(num == )
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return ;
}

uva-1339Ancient Cipher的更多相关文章

  1. UVA 306 Cipher

    题意 :lucky cat里有翻译.英文也比较好懂. 很容易发现有周期然后就拍就好了 注意每组数据后边都有空行 包括最后一组.一开始以为最后一组没有空行.唉.. #include <map> ...

  2. UVa 1339 Ancient Cipher --- 水题

    UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...

  3. Ancient Cipher UVA - 1339

      Ancient Roman empire had a strong government system with various departments, including a secret s ...

  4. uva 1339 Ancient Cipher

    大意:读入两个字符串(都是大写字母),字符串中字母的顺序可以随便排列.现在希望有一种字母到字母的一一映射,从而使得一个字符串可以转换成另一个字符串(字母可以随便排列)有,输出YES:否,输出NO:ex ...

  5. 【UVA 1586】Ancient Cipher

    题 题意 给你一个只含CHON的有机物的化学式如C6H5OH求相对分子质量 分析 ... 代码 switch #include<cstdio> #include<cctype> ...

  6. UVa LA 3213 - Ancient Cipher 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  7. 【例题 4-1 UVA - 1339】 Ancient Cipher

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 位置其实都没关系了. 只要每个字母都有对应的字母,它们的数量相同就可以了. 求出每种字母的数量. 排序之后. 肯定是要一一对应的. ...

  8. UVa1399.Ancient Cipher

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

  9. JAVA实现AES 解密报错Input length must be multiple of 16 when decrypting with padded cipher

    加密代码 /**解密 * @param content 待解密内容 * @param password 解密密钥 * @return */ public static byte[] decrypt(b ...

  10. POJ1026 Cipher(置换的幂运算)

    链接:http://poj.org/problem?id=1026 Cipher Time Limit: 1000MS   Memory Limit: 10000K Total Submissions ...

随机推荐

  1. logstash之multiline插件,匹配多行日志

    在外理日志时,除了访问日志外,还要处理运行时日志,该日志大都用程序写的,比如log4j.运行时日志跟访问日志最大的不同是,运行时日志是多行,也就是说,连续的多行才能表达一个意思. 在filter中,加 ...

  2. Redis简介、与memcached比较、存储方式、应用场景、生产经验教训、安全设置、key的建议、安装和常用数据类型介绍、ServiceStack.Redis使用(1)

    1.NOSQL简介 nosql的产生并不是要彻底的代替关系型数据库,而是作为传统关系型数据库的一个补充. Facebook和360使用Cassandra来存储海量社交数据 Twitter在其url抓取 ...

  3. 【JAVA集合框架之工具类】

    一.概述 JAVA集合框架中有两个很重要的工具类,一个是Collections,另一个是Arrays.分别封装了对集合的操作方法和对数组的操作方法,这些操作方法使得程序员的开发更加高效. public ...

  4. [LeetCode] Binary Tree Zigzag Level Order Traversal

    Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...

  5. 解决postgresql -- ERROR: 42601: query has no destination for result data

    I am learning Npgsql and PostgreSQL. I am unable to define the output parameter correctly. What am I ...

  6. IOS 100 - 1 开工闲聊

    1 前言 现在的行情,作为码农,ios 普遍比c# 的待遇好上不少.感觉就如清洁工人,扫厕所干的再高效和干净,一个月就那么点微薄的收入.当然你可以选择去香港打扫卫生间,那里的行情据说清洁工也破万了.说 ...

  7. C# 文件读取方法,自己写的例子,保存一下,备用

    /// <summary> /// 将output.config内容传到app.config /// </summary> string ReadString; //两个地址 ...

  8. FP-Growth算法及演示程序

    FP-Growth算法 FP-Growth(频繁模式增长)算法是韩家炜老师在2000年提出的关联分析算法,它采取如下分治策略:将提供频繁项集的数据库压缩到一棵频繁模式树(FP-Tree),但仍保留项集 ...

  9. hdu 4028 2011上海赛区网络赛H dp+map离散

    一开始用搜索直接超时,看题解会的 #include<iostream> #include<cstdio> #include<map> #include<cst ...

  10. linux ssh key配置方法

    转自:http://blog.csdn.net/zzk197/article/details/7915307 一:简洁的配置文件[root@cisco ~]# vi /etc/ssh/sshd_con ...