码迷,mamicode.com
首页 > 其他好文 > 详细

POJ_2159 Ancient Cipher

时间:2018-04-24 22:26:54      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:names   需要   sort   cstring   problem   ret   org   简单的   个数   

题目链接: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

标签:names   需要   sort   cstring   problem   ret   org   简单的   个数   

原文地址:https://www.cnblogs.com/zl-nirvana/p/8934085.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!