Bailian2820 Ancient Cryptogram【密码】

2820: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.
输入
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.
输出
If the original string can be converted to the encrypted string by replacing and reodering, output "YES", otherwise "NO".
样例输入
JWPUDJSTVP
VICTORIOUS
样例输出
YES

问题链接Bailian2820 Ancient Cryptogram
问题描述:(略)
问题分析:(略)
程序说明
    本题与参考链接是同一题,使用参考链接的程序提交也AC。
参考链接UVA1339 UVALive3213 POJ2159 ZOJ2658 Ancient Cipher【密码】
题记:(略)

AC的C语言程序如下:

/* UVA1339 UVALive3213 POJ2159 ZOJ2658 Ancient Cipher */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>

#define LETTERNUM 26
#define MAXN     100

int cmp(const void * a, const void * b)
{
    return *(int *)a - *(int *)b;
}

int main(void)
{
    char s[MAXN+1], t[MAXN+1];
    int counts[LETTERNUM], countt[LETTERNUM], len, flag, i;

    while(scanf("%s", s) != EOF) {
        scanf("%s", t);

        memset(counts, 0, sizeof(counts));
        memset(countt, 0, sizeof(countt));

        len = strlen(s);
        for(i=0; i<len; i++) {
            counts[s[i]-'A']++;
            countt[t[i]-'A']++;
        }

        qsort(counts, LETTERNUM, sizeof(counts[0]), cmp);
        qsort(countt, LETTERNUM, sizeof(countt[0]), cmp);

        flag = 1;
        for(i=0; i<LETTERNUM; i++)
            if(counts[i] != countt[i]) {
                flag = 0;
                break;
            }

        printf("%s\n", flag ? "YES" : "NO");
    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/tigerisland45/p/10094308.html