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;
}
题目链接: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;
}
相关文章推荐
- Ancient Cipher UVA-1339
- 算法竞赛入门经典第四章例题4-1 Ancient Cipher UVA - 1339
- UVa 1339 Ancient Cipher
- 例题4-1 古老的密码(Ancient Cipher, NEERC 2004, UVa1339)
- UVa 1339 - Ancient Cipher
- UVA 1339 - Ancient Cipher
- uva 1339 Ancient Cipher(字符串处理)
- UVa 1339 - Ancient Cipher
- UVA1339- Ancient Cipher
- Uva - 1339 - Ancient Cipher
- 【例题 4-1 UVA - 1339】 Ancient Cipher
- UVa-1339 - Ancient Cipher
- UVa 1339 - Ancient Cipher
- K - Ancient Cipher UVA - 1339
- Uva - 1339 - Ancient Cipher
- UVa-1339 - Ancient Cipher
- uva 1339 Ancient Cipher
- UVa 1339 - Ancient Cipher
- UVA 1339 Ancient Cipher(映射 | 想法)
- UVa1339 Ancient Cipher