hihocoder_week197逆序单词

题目链接: http://hihocoder.com/problemset/problem/1366

解题思路: 根据题目给出的条件,只需要统计每个单词和其逆序出现的次数就可以了。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 map<string, int> mp;
 5 int n;
 6 
 7 int main()
 8 {
 9     while (cin>>n)
10     {
11         mp.clear();
12         string tmp;
13         for (int i=1;i<=n;++i)
14         {
15             cin>>tmp;
16             mp[tmp]+=1;
17             reverse(tmp.begin(), tmp.end());
18             mp[tmp]+=1;
19         }
20         int ans = 0;
21         for (auto i:mp)
22         {
23             if (i.second==2)
24             {
25                 ++ans;
26             }
27         }
28         cout<<ans/2<<endl;
29     }
30     return 0;
31 }

 

posted @ 2018-04-18 21:53  只会一点暴力  阅读(172)  评论(0编辑  收藏  举报