题意:给出两个长度相等的大写字母序列,问能否从一个序列映射到另一个序列(序列长度 <= 100)。
——>>对于每个序列,统计各个字母出现的次数,将26个字母出现的次数排序,即看出现的次数是否一一对应。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 100 + 10;
const int maxm = 26;
int main()
{
char s1[maxn], s2[maxn];
int a[maxm], b[maxm], i;
while(scanf("%s%s", s1, s2) == 2){
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
int len = strlen(s1);
for(i = 0; i < len; i++){
a[s1[i]-'A']++;
}
len = strlen(s2);
for(i = 0; i < len; i++){
b[s2[i]-'A']++;
}
sort(a, a + maxm);
sort(b, b + maxm);
bool ok = 1;
for(i = 0; i < maxm; i++){
if(a[i] != b[i]){
ok = 0;
break;
}
}
if(ok) printf("YES\n");
else printf("NO\n");
}
return 0;
}