uva 1339 Ancient Cipher
大意:
读入两个字符串(都是大写字母),字符串中字母的顺序可以随便排列。
现在希望有一种字母到字母的一一映射,从而使得一个字符串可以转换成另一个字符串(字母可以随便排列)
有,输出YES;否,输出NO;
exp:
输入
HAHA
HEHE
输出
YES
可以将A→E,或E→A;
关键在于,问题简化:
因为不用考虑字母位置,所以可以分别统计两个字符串中不同字母出现次数,计入数组counts1和counts2。
那么,怎么知道谁和谁对应呢?
这里面有个隐含条件:如果A→B,那么A在1数组出现的次数和B在2数组中出现的次数一定是一样的!
或者说,如果A出现的频率是30%,那么B也是30%。
即二者的地位是相同的。
所以,通过sort将counts1和counts2排序,并相互比较;如果二者一模一样,那就可以直接在对应字母间建立映射关系;否则,一定没法对应。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int maxl=;
const int maxalpa=;
char sup[maxl];
char sub[maxl];
int counts1[maxalpa],counts2[maxalpa];
int l; int main()
{
while(scanf("%s%s",sup,sub)!=EOF)
{
memset(counts1,,sizeof(counts1));
memset(counts2,,sizeof(counts2)); l=strlen(sup);
for(int i=;i<l;i++)
{
counts1[sup[i]-'A']++;
counts2[sub[i]-'A']++;
}
sort(counts1,counts1+);
sort(counts2,counts2+);
if(!memcmp(counts1,counts2,sizeof(counts1)))
printf("YES\n");
else
printf("NO\n"); memset(sup,,sizeof(sup));
memset(sub,,sizeof(sub));
}
return ;
}
uva 1339 Ancient Cipher的更多相关文章
- UVa 1339 Ancient Cipher --- 水题
UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...
- UVa1399.Ancient Cipher
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- uva--1339 - Ancient Cipher(模拟水体系列)
1339 - Ancient Cipher Ancient Roman empire had a strong government system with various departments, ...
- Poj 2159 / OpenJudge 2159 Ancient Cipher
1.链接地址: http://poj.org/problem?id=2159 http://bailian.openjudge.cn/practice/2159 2.题目: Ancient Ciphe ...
- Ancient Cipher UVa1339
这题就真的想刘汝佳说的那样,真的需要想象力,一开始还不明白一一映射是什么意思,到底是有顺序的映射?还是没顺序的映射? 答案是没顺序的映射,只要与26个字母一一映射就行 下面给出代码 //Uva1339 ...
- poj 2159 D - Ancient Cipher 文件加密
Ancient Cipher Description Ancient Roman empire had a strong government system with various departme ...
- POJ2159 Ancient Cipher
POJ2159 Ancient Cipher Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 38430 Accepted ...
- POJ2159 ancient cipher - 思维题
2017-08-31 20:11:39 writer:pprp 一开始说好这个是个水题,就按照水题的想法来看,唉~ 最后还是懵逼了,感觉太复杂了,一开始想要排序两串字符,然后移动之类的,但是看了看 好 ...
- 2159 -- Ancient Cipher
Ancient Cipher Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 36074 Accepted: 11765 ...
随机推荐
- [转]Meta http-equiv属性详解
http-equiv顾名思义,相当于http的文件头作用,它可以向浏览器传回一些有用的信息,以帮助正确和精确地显示网页内容,与之对应的属性值为content,content中的内容其实就是各个参数的变 ...
- php-sql-parser sql防注入脚本
<?php /** * SQL Parser from: http://code.google.com/p/php-sql-parser/ * License: New BSD */ class ...
- 部署wcf到IIS时的问题
1,部署到IIS后,在浏览器可以访问.但客户端添加服务引用时,出现错误: - 下载“http://admin-pc/IISHostService/Service1.svc?xsd=xsd0”时出错.- ...
- pip和easy_install更换使用国内源
因为论文原因,需要使用python安装一些自然语言库,但是使用pip或easy_install安装包时,总是超时(中国特色搞得事:-D),没有办法,上网查资料解决问题~~,在网上找到的方法都是说更换国 ...
- android面试题
1. 请描述一下Activity 生命周期. 答: 如下图所示.共有七个周期函数,按顺序分别是: onCreate(), onStart(), onRestart(), onResume(), onP ...
- 学习UFT11.5历程(二)
1. QTP对象TO与RO TO: test object. 本地对象库里的封装对象 RO:run object. 运行封装对象 和TO.RO相关的几个函数有: GetTOProperty(“属性名” ...
- viewPager + fragment
有两种实现方式,一种是 fragmentActivity + FragmentPagerAdapter (Fragment,FragmentManager需要导包:android.support.v4 ...
- 一个div相对于外层的div水平和垂直居中
我自己感觉,第四种比较常用 <title>无标题文档</title><style> .parent { width:800px; ...
- VNC SERVER配置
vnc的配置网上有很多 普通用户的配置没有怎么写 根据下面这个说法 https://www.digitalocean.com/community/tutorials/how-to-install-an ...
- js控制 input框中输入数字时,累计求和
$('.cc input').bind('input propertychange', function(){ var total = 0; $("input").each(fun ...