1. 程式人生 > >POJ_2159 Ancient Cipher

POJ_2159 Ancient Cipher

互轉 LG 題目 string 只需要 return span stream sort

題目鏈接: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 }

POJ_2159 Ancient Cipher