Ancient Cryptogram【水题】

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

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

瘾ิۣۖิۣۖิۣۖิꦿ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值