la 3213 Ancient Cipher
来源:互联网 发布:新开淘宝店铺 编辑:程序博客网 时间:2024/06/06 08:30
题目链接: 点击打开链接
题目大意: 给定两个长度均为n的字符串,判断其中一个字符串重新排列后,每个字母能否和另一个字符串的字母一一对应.比如ABB和CDD.
思路: 字符串匹配
分析:
1. 两个字符串如果能一一对应,那么对应的字母出现次数一定是相同的.
2. 因此对每个字符串,计算所有字母出现的次数,再依次比对这些次数.如果有不相同的次数说明无法一一对应.
代码:
#include <iostream>#include <algorithm>#include <string>#include <cstdio>#include <memory.h>using namespace std;const int maxn = 30;int main(){string a, b;while (cin >> a >> b){int a_count[maxn], b_count[maxn], i;memset(a_count, 0, sizeof(a_count));memset(b_count, 0, sizeof(b_count));int l = a.length();for (i = 0; i < l; ++i){++a_count[a[i]-'A'];++b_count[b[i]-'A'];}sort(a_count, a_count+26);sort(b_count, b_count+26);for (i = 25; i >= 0; --i)if (a_count[i] != b_count[i])break;if (i == -1)printf("YES\n");elseprintf("NO\n");}return 0;}
- LA 3213 Ancient Cipher
- LA 3213 - Ancient Cipher
- la 3213 Ancient Cipher
- LA 3213 Ancient Cipher -
- LA 3213 Ancient Cipher , NEERC 2004
- UVALive - 3213 Ancient Cipher
- UVALive - 3213 Ancient Cipher
- UVALive 3213 Ancient Cipher(坑呀.........)
- Ancient Cipher
- Ancient Cipher
- Ancient Cipher
- Ancient Cipher
- Ancient Cipher
- Ancient Cipher
- Ancient Cipher
- UVALive - 3213 Ancient Cipher (sort)
- POJ2159 Ancient Cipher
- Ancient Cipher--POJ2159
- 关系型数据库设计
- 滑雪(dp+深搜)
- WebSphere Message Broker(13)-- 实现高可用(一) 水平集群 [ 配置和管理多实例代理 ]
- find和grep的使用
- Android Radio Interface Layer(RIL)
- la 3213 Ancient Cipher
- Linux下rz,sz与ssh的配合使用
- 让浏览器不记录CSS缓存
- 第十三周-求出并输出Fibnacci序列的第20个数(迭代方式)
- WebSphere Message Broker(14)-- 实现高可用(二) 垂直集群 [WebSphere MQ集群 ] 、 水平垂直集群
- Cocos2d-x win7 + vs2010 配置图文详解
- ndk编译c可执行程序(jni 入门)
- 我还想要在北京买房~~每年都比较下
- 随机猜数