POJ_2159 Ancient Cipher

题目链接:http://poj.org/problem?id=2159

这题还是很简单的,只需要开两个数组用来存不同字母出现的次数,然后排下序,如果两个数组相等,那就一定能相互转换。

 1 #include <iostream>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 
 6 const int maxn = 101;
 7 
 8 int main()
 9 {
10     char s1[maxn], s2[maxn];
11     int len, book1[26] = { 0 },book2[26] = { 0 };
12     cin >> s1 >> s2;
13     len = strlen(s1);
14     for (int i=0;i<len;i++)
15     {
16         book1[s1[i] - 'A']++;
17         book2[s2[i] - 'A']++;
18     }
19     sort(book1, book1 + 26);
20     sort(book2, book2 + 26);
21     for (int i=0;i<26;i++)
22     {
23         if (book1[i]!=book2[i])
24         {
25             cout << "NO" << endl;
26             return 0;
27         }
28     }
29     cout <<"YES"<< endl;
30     return 0;
31 }

猜你喜欢

转载自www.cnblogs.com/zl-nirvana/p/8934085.html