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

[ Introduction to algorithm competition classic ]Ancient Cipher, NEERC 2004,UVa1339 More articles about

  1. (Step1-500 topic )UVaOJ+ Introduction to algorithm competition classic + Challenge programming +USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html The topics given below amount to 560 Avenue , It's also close to getting rid of repetition 500 topic , As ACMer Training Step1, use 1 year ...

  2. [ Brush problem ] Introduction to algorithm competition classic 3-12/UVa11809

    All the specific topics in the book :http://pan.baidu.com/s/1hssH0KO subject : Introduction to algorithm competition classic 3-4/UVa11809:Floating-Point Numbers Code : //UVa11 ...

  3. [ Brush problem ] Introduction to algorithm competition classic 3-10/UVa1587 3-11/UVa1588

    All the specific topics in the book :http://pan.baidu.com/s/1hssH0KO subject : Introduction to algorithm competition classic 3-10/UVa1587:Box Code : //UVa1587 - Box #include&l ...

  4. [ Brush problem ] Introduction to algorithm competition classic 3-7/UVa1368 3-8/UVa202 3-9/UVa10340

    All the specific topics in the book :http://pan.baidu.com/s/1hssH0KO All are < Introduction to algorithm competition classic ( The second edition )> The subject of , The title doesn't say ( The second edition ) subject : Introduction to algorithm competition classic 3-7/UVa13 ...

  5. [ Brush problem ] Introduction to algorithm competition classic 3-4/UVa455 3-5/UVa227 3-6/UVa232

    All the specific topics in the book :http://pan.baidu.com/s/1hssH0KO subject : Introduction to algorithm competition classic 3-4/UVa455:Periodic Strings Code : //UVa455 #inclu ...

  6. [ Brush problem ] Introduction to algorithm competition classic 3-1/UVa1585 3-2/UVa1586 3-3/UVa1225

    All the specific topics in the book :http://pan.baidu.com/s/1hssH0KO( I also found it on the Internet pdf, But I don't remember where I got it , Just upload it again ) PS: For the first time, I wrote a blog to share my code , I don't know about c ...

  7. Introduction to algorithm competition classic training guide ——UVA 11300 preading the Wealth

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

  8. Introduction to algorithm competition classic + Challenge programming +USACO

    The topics given below amount to 560 Avenue , It's also close to getting rid of repetition 500 topic , As ACMer Training Step1, use 1 Year to 1 It will be completed in half a year . Lay a solid foundation , whole . One .UVaOJ http://uva.onlinej ...

  9. Introduction to algorithm competition classic LA 4329( Tree array )

    The question : A row of people with different abilities , It is stipulated that the referee's serial number can only be between two people , And the skill value can only be between two people problem : < Introduction to algorithm competition classic - Training guide > Analysis of : Code up : #include<iostre ...

Random recommendation

  1. pod install slow

    Recently used CocoaPods To add a third-party class library , Whether it's execution pod install still pod update It's all stuck Analyzing dependencies Immobility The reason is that when the above two commands are executed, they will be upgraded Co ...

  2. ASP.NET Connect MySQL database The detailed steps

    ASP.NET The default database is MS SQL Server, Microsoft's database products . in fact , If you don't count the cost ,Windows Server + IIS + MS SQL Server + ASP.NET It's a net ...

  3. Android Of root Study

    Android The kernel of is Linux, therefore Android obtain root Actually sum Linux obtain root Authority is one thing . stay Linux Lower access root The time of authority is to execute sudo perhaps su, Next, the system will prompt you to enter root ...

  4. Jinan Qingbei school travel notes Day 4.

    Before you know it , It's more than half of the journey . Basically familiar with the environment here , It also means that I should be leaving soon . Tomorrow and the day after tomorrow, there will be the last four simulation games , Although I can't win the prize with my strength , But I will try my best to be myself . I've probably reflected on these days , Its ...

  5. ubuntu 16.04 Empty log Method of file

    because ubuntu Log files syslog and kern.log Growing all the time , After a while, the root folder is not enough , Use the following command to clean up  sudo -i  Then enter the password , perform : echo > /var/log ...

  6. 【LOJ6053】 Simple functions (min_25 sieve )

    Topic LOJ Answer key Poke it here #include<iostream> #include<cstdio> #include<cstdlib> #include<cs ...

  7. Java.ftp Upload and download

    1:jar Of maven References to : 1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="ht ...

  8. INSTALL_FAILED_MISSING_SHARED_LIBRARY

    target Choose... From the options Google APIs. Pictured .

  9. window.addEventListener Remember to delete the binding event

    Doing it postMessage When communication ,window.addEventListener For bound events, remember to remove fall Just like setTime equally , Otherwise, it takes up memory resources

  10. HDU 2121——Ice_cream’s world II——————【 Minimum tree 、 Indefinite root 】

    Ice_cream’s world II Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...