In ancient wars, cryptogram was applied widely. There were two types of
method to encrypt a string.
The first one was replacing, which replaced every character by another. It
should use a conversion table to map the original letters to the encryped
letters. For example, if the conversion table was "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
to "BCDEFGHIJKLMNOPQRSTUVWXYZA" and the original string was "HELLO", the
encryped string should be "IFMMP".
The second one was reodering. It should use a reordering table such as
<2, 1, 5, 4, 3, 7, 6, 10, 9, 8>. Apply it to the original string
"VICTORIOUS", we got "IVOTCIRSUO" as the encrypted string.
Now, give you an original string and an encryped string. Your task is to
answer whether the original string can be converted to the encryped string using
replacing AND reodering.
Input
Line 1: encrypted string, which contains only capital letters.
Line 2: original string, which contains only capital letter.
The length of two strings are both no more than 100.
Output
If the original string can be converted to the encrypted string by replacing and reodering, output "YES", otherwise "NO".
Sample Input
JWPUDJSTVP VICTORIOUS
Sample Output
YES
题解:
题目中所说的改变和交换其实都是任意的,通俗点说,,想怎么换就怎么换。所以,根本就没有任何必要来考虑题目中所说的交换,直接统计单词的个数然后进行判断即可!!!
AC代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include<iostream>
using namespace std;
char s1[1500], s2[1500];
int sum1[50], sum2[50];
int main () {
scanf("%s %s", s1, s2);
int len1 = strlen(s1);
for (int i = 0; i < len1; i++) sum1[(int)s1[i] - 'A' + 1]++;
//cout<<sum1[26]<<' '<<sum1[24]<<endl;
int len2 = strlen(s2);
for (int i = 0; i < len2; i++) sum2[(int)s2[i] - 'A' + 1]++;
for (int i = 1; i <= 26; i++) {
for (int j = 1; j <= 26; j++)
if (sum1[i] == sum2[j]) {
//cout<<i<<' '<<j<<endl;
sum1[i] = 0;
sum2[j] = 0;
break;
}
if (sum1[i] > 0) {
printf("NO");
exit(0);
}
}
printf("YES");
return 0;
}