poj2159Ancient Cipher
2016-05-08 13:59
183 查看
水题一道,然而废了不少功夫,频率一样就行,排个序就OK了,不过刚开始以为只能加1,其实可以加很多,题意理解错了
#include <iostream> #include <string.h> #include <algorithm> using namespace std; string s1,s2; int a1[150],a2[150]; int main() { while(cin>>s1>>s2) { int ans=0,k=1; for(int i=0; i<s1.length(); i++) { a1[i]=0; a2[i]=0; } bool flag=0; for(int i=0; i<s1.length(); i++) a1[s1[i]-'A']++; for(int i=0; i<s2.length(); i++) a2[s2[i]-'A']++; sort(a1,a1+30); sort(a2,a2+30); for(int i=0; i<=30; i++) { if(a1[i]==a2[i]) continue; else { flag=1; break; } } if(flag==1) cout<<"NO"<<endl; else cout<<"YES"<<endl;; for(int i=0; i<s1.length(); i++) s1.clear(); for(int i=0; i<s2.length(); i++) s2.clear(); } return 0; }
相关文章推荐
- 初学ACM - 组合数学基础题目PKU 1833
- 【HDU 5366】The mook jong 详解
- POJ ACM 1001
- POJ ACM 1002
- 1611:The Suspects
- POJ1089 区间合并
- POJ 2159 Ancient Cipher
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- POJ 2773 HAPPY 2006
- POJ 3090 Visible Lattice Points
- POJ-2409-Let it Bead&&NYOJ-280-LK的项链
- POJ-1695-Magazine Delivery-dp
- POJ1523 SPF dfs
- POJ-1001 求高精度幂-大数乘法系列
- POJ-1003 Hangover
- POJ-1004 Financial Management
- POJ1050 最大子矩阵和
- 用单调栈解决最大连续矩形面积问题
- 2632 Crashing Robots的解决方法