POJ 2159
来源:互联网 发布:枫叶知秋 编辑:程序博客网 时间:2024/06/08 17:32
题意
举例说说这一题吧,比如下面
ABBCFEA(假设为dst)
CCGGHJB(假设为src)
不关心怎么从src变到dst,我先qsort一遍,两者就变成:
AABBCEF
BCCGGHJ
不深度题目,人工的都以为这个是NO.
但非也,我们再找一下两个串的相同字母数字序列.两者分别是:
22111
12211
这个你应该了解吧,就是AA为2,BB为2,C为1,E为1,F为1.
然后再把两串数字qsort就是
11122
11122
再比较一下,一样就YES了,否则NO.
代码要点
用一个非常精妙的存储结构
is[s1[i]-‘A’]++; 这个很厉害,把每个字符都进行了定位,并且没有重复
代码
// POJ 2159#include <iostream>#include <algorithm>#include <string>#define max 30using namespace std;int main(){ int is1[max],is2[max],i; memset(is1,max,sizeof(int)*max); memset(is2,max,sizeof(int)*max); string s1,s2; cin>>s1>>s2; for(i=0;i<s1.length();i++){ is1[s1[i]-'A']++; is2[s2[i]-'A']++; } sort(is1,is1+26); sort(is2,is2+26); for(i=0;i<26;i++){ if(is1[i]==is2[i]){ continue; } else{ cout<<"NO"<<endl; return 0; } } cout<<"YES"<<endl; return 0;}
0 0
- POJ-2159
- POJ 2159
- POJ 2159
- poj 2159
- poj-2159
- poj 2159
- POJ 2159
- POJ-2159
- POJ 2159
- poj 2159
- poj 2159
- poj 2159
- poj 2159
- POJ 2159 字符串加密
- POJ 2159 Ancient Cipher
- [poj] 水题2159
- poj 2159 : Ancient Cipher
- poj 2159 字母映射
- 九度OJ 1030:毕业bg (01背包、DP)
- C#中的 int? int??是什么意思
- iOS8以后第三方键盘,获取高度为0的问题
- 67Add Binary
- Mvc Html.BeginForm 方式提交Form前验证
- POJ 2159
- linux文件的隐藏属性chattr,lsattr
- iOS开发常用的集中设计模式
- UFT工具
- Android学习Broadcast Receiver(广播接收者) 注意事项
- maven报错
- 测试对象管理—共享对象库
- Mac终端出现“terminal pointer being freed was not allocated…”解决办法
- C语言基础(一)编译、数据类型、注释、代码块