您的位置:首页 > 其它

古代密码 字符串水题

2016-11-09 17:43 225 查看
原题传送门

题目描述

吐槽

正经的题解

听说NOI题库又开始加题了2333,对于它的题目质量我不做任何评价

原题传送门

题目描述:

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.

吐槽:

果然是NOI题库的风格,这个鬼中文题目看了三遍都没看懂它是啥意思,还是英文题目稍微靠谱点,,

正经的题解:

题目中所说的改变和交换其实都是任意的,,通俗点说,,想怎么换就怎么换。。所以,根本就没有任何必要来考虑题目中所说的交换,直接统计单词的个数然后进行判断即可

PS:其实可以把每个单词中字母的数量统计出来然后排个序再处理,,然而数据范围太小了,,省了,,

#include <cstdio>
#include <cstring>
#include <algorithm>

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]++;
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]) {
sum1[i] = 0;
sum2[j] = 0;
break;
}
if (sum1[i] > 0) {
printf("NO");
exit(0);
}
}
printf("YES");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: