POJ_2159 Ancient Cipher

Topic link: http://poj.org/problem?id=2159

This problem is still very simple. You only need to open two arrays to store the number of occurrences of different letters, and then sort them in descending order. If the two arrays are equal, they must be converted to each other.

 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 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324792357&siteId=291194637