大意:
读入两个字符串(都是大写字母),字符串中字母的顺序可以随便排列。
现在希望有一种字母到字母的一一映射,从而使得一个字符串可以转换成另一个字符串(字母可以随便排列)
有,输出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的更多相关文章

  1. UVa 1339 Ancient Cipher --- 水题

    UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...

  2. UVa1399.Ancient Cipher

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

  3. uva--1339 - Ancient Cipher(模拟水体系列)

    1339 - Ancient Cipher Ancient Roman empire had a strong government system with various departments, ...

  4. Poj 2159 / OpenJudge 2159 Ancient Cipher

    1.链接地址: http://poj.org/problem?id=2159 http://bailian.openjudge.cn/practice/2159 2.题目: Ancient Ciphe ...

  5. Ancient Cipher UVa1339

    这题就真的想刘汝佳说的那样,真的需要想象力,一开始还不明白一一映射是什么意思,到底是有顺序的映射?还是没顺序的映射? 答案是没顺序的映射,只要与26个字母一一映射就行 下面给出代码 //Uva1339 ...

  6. poj 2159 D - Ancient Cipher 文件加密

    Ancient Cipher Description Ancient Roman empire had a strong government system with various departme ...

  7. POJ2159 Ancient Cipher

    POJ2159 Ancient Cipher Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38430   Accepted ...

  8. POJ2159 ancient cipher - 思维题

    2017-08-31 20:11:39 writer:pprp 一开始说好这个是个水题,就按照水题的想法来看,唉~ 最后还是懵逼了,感觉太复杂了,一开始想要排序两串字符,然后移动之类的,但是看了看 好 ...

  9. 2159 -- Ancient Cipher

    Ancient Cipher Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 36074   Accepted: 11765 ...

随机推荐

  1. 解决iscroll5在手机页面上onclick事件失效

    Iscroll.js使用之后页面上面A标签的onclick事件无效了   解决办法 实例化IScroll的时候把preventDefault设为false,默认为true var myScroll; ...

  2. Nginx基础知识之————RTMP模块中的中HLS专题(翻译文档)

    一.在Nginx配置文件的RTMP模块中配置hls hls_key_path /tmp/hlskeys; 提示错误信息: nginx: [emerg] the same path name " ...

  3. js 中与元素有关的高度

    1, 平常都经常用 document.documentElement.clientWidth 或 document.documentElement.clientHeight 来获取页面的宽度和高度, ...

  4. Pod 的安装

    1.如果之前已经安装过的 gem list --local | grep cocoapods 会看到如下输出: cocoapods (1.1.1)cocoapods-deintegrate (1.0. ...

  5. 安卓跳转到GPS设置界面

      /** * 监听GPS */ private void initGPS() { LocationManager locationManager = (LocationManager) this . ...

  6. HBase 的表结构

    HBase 的表结构 2016-10-13 杜亦舒 HBase 是一个NoSQL数据库,用于处理海量数据,可以支持10亿行百万列的大表,下面就了解一下数据是如何存放在HBase表中的 关系型数据库的表 ...

  7. 解决ora-00054 Oracle锁表问题

    1.运行sql: select session_id from v$locked_object;   查出锁表的session,可能很多,正常是没有的 2.SELECT sid, serial#, u ...

  8. 不注册Tomcat服务,运行Tomcat不弹出JAVA控制台窗口

    http://blog.csdn.net/yangholmes_blog/article/details/52881296

  9. CSS3--transform

    transform:向元素应用2D或3D转换,该属性允许我们对属性旋转,缩放,移动,或倾斜. transfrom:none:定义不进行转换 transfrom:matrix(n,n,n,n,n,n); ...

  10. css 表格

    1.给元素的display属性添加为以下值 table : <table> table-caption :<caption> table-cell : <td> t ...