您的位置:首页 > 其它

Uva - 1339 - Ancient Cipher

2013-07-31 10:59 393 查看
题意:给出两个长度相等的大写字母序列,问能否从一个序列映射到另一个序列(序列长度 <= 100)。

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=457&problem=4085

——>>对于每个序列,统计各个字母出现的次数,将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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: