摘要: 巧妙的解法,借鉴了别人的 只要看字母频率就可以直接得出结论

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

int main()
{
    char cipher[105];
    char origin[105];
    int ctime[26] = {0};
    int otime[26] = {0};
    scanf("%s%s", cipher, origin);

    for(int i = 0; i < strlen(cipher); i++)
    {
        ctime[cipher[i] - 'A']++;
        otime[origin[i] - 'A']++;
    }
    qsort(ctime, 26, sizeof(int), cmp);
    qsort(otime, 26, sizeof(int), cmp);
    for(int i = 0; i < 26; i++)
    {
        if(ctime[i] != otime[i])
        {
            printf("NO");
            return 0;
        }
    }
    printf("YES");
    return 0;
}