UVa1339 古老的密码
代码:
// UVa1339
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int cmp(const void *a, const void *b)
{
return *(int *) a - *(int *)b;
}
int main()
{
int a[26] = {0};
int b[26] = {0};
char s[105];
char g[105];
while(scanf("%s", s) != EOF)
{
scanf("%s", g);
int lens = strlen(s);
int leng = strlen(g);
int ok = 1;
if (lens != leng)
ok = 0;
else
{
for (int i = 0; i < lens; i++)
{
a[s[i] - 'A']++;
b[g[i] - 'A']++;
}
qsort(a, 26, sizeof(int), cmp);
qsort(b, 26, sizeof(int), cmp);
for (int i = 0; i < 26; i++)
{
if (a[i] != b[i])
ok = 0;
}
}
if (ok)
printf("YES\n");
else
printf("NO\n");
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(s, 0, sizeof(s));
memset(g, 0, sizeof(g));
}
return 0;
}
测试结果: