poj 2159 Ancient Cipher(水)
由于顺序是可以改变的. 所以考虑是否可以映射.只要存在字母对应出现的次数都相同.那么就可以通过映射得到. 具体是开一个数组记录每个字母出现的次数… 然后sort
1/*************************************************************************
2 > File Name: code/poj/2159.cpp
3 > Author: 111qqz
4 > Email: rkz2013@126.com
5 > Created Time: 2015年09月23日 星期三 19时04分34秒
6 ************************************************************************/
7
8#include<iostream>
9#include<iomanip>
10#include<cstdio>
11#include<algorithm>
12#include<cmath>
13#include<cstring>
14#include<string>
15#include<map>
16#include<set>
17#include<queue>
18#include<vector>
19#include<stack>
20#include<cctype>
21#define y1 hust111qqz
22#define yn hez111qqz
23#define j1 cute111qqz
24#define ms(a,x) memset(a,x,sizeof(a))
25#define lr dying111qqz
26using namespace std;
27#define For(i, n) for (int i=0;i<int(n);++i)
28typedef long long LL;
29typedef double DB;
30const int inf = 0x3f3f3f3f;
31const int N=30;
32string st1,st2;
33int len;
34int a[N],b[N];
35
36
37bool cmp( int a,int b)
38{
39 if (a>b) return true;
40 return false;
41}
42int main()
43{
44 #ifndef ONLINE_JUDGE
45 freopen("in.txt","r",stdin);
46 #endif
47 ms(a,0);
48 ms(b,0);
49 cin>>st1>>st2;
50 len = st1.length();
51 // cout<<st1<<endl<<st2<<endl;
52 for ( int i = 0 ; i < len ; i ++)
53 {
54 int tmp = st1[i]-'A';
55 a[tmp]++;
56 tmp = st2[i]-'A';
57 b[tmp]++;
58 }
59
60 sort(a,a+26,cmp);
61 sort(b,b+26,cmp);
62 // for ( int i = 0 ; i < 26 ; i++) cout<<"a[i]:"<<a[i]<<" b[i]"<<b[i]<<endl;
63
64 bool flag = true;
65 for ( int i = 0 ; i < 26 ; i++)
66 {
67 if (a[i]!=b[i])
68 {
69 flag = false;
70 break;
71 }
72 }
73 if (flag)
74 {
75 puts("YES");
76 }
77 else
78 {
79 puts("NO");
80 }
81
82
83 #ifndef ONLINE_JUDGE
84 fclose(stdin);
85 #endif
86 return 0;
87}