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

POJ 1002 - 487-3279 STL

时间:2016-08-13 15:28:16      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

先把不是标准格式的字符串变成标准格式
再输出出现两次以上的标准串和出现的次数
不然输出 "No duplicates."

 1 #include <iostream>
 2 #include <cstring>
 3 #include <string>
 4 #include <map>
 5 #include <vector>
 6 #include <algorithm>
 7 using namespace std;
 8 int n;
 9 map<char,char> num;
10 map<string,int> mp;
11 string a;
12 char s[100005];
13 vector<string> ans;
14 int main()
15 {
16     num.clear();
17     mp.clear();
18     ans.clear();
19     num[A] = num[B] = num[C] = 2;
20     num[D] = num[E] = num[F] = 3;
21     num[G] = num[H] = num[I] = 4;
22     num[J] = num[K] = num[L] = 5;
23     num[M] = num[N] = num[O] = 6;
24     num[P] = num[R] = num[S] = 7;
25     num[T] = num[U] = num[V] = 8;
26     num[W] = num[X] = num[Y] = 9;
27     cin>>n;
28     for (int i = 1; i <= n; i++)
29     {
30         a.clear();
31         cin>>s;
32         for (int i = 0; s[i] != \0; i++)
33         {
34             if(s[i]>=0 && s[i]<=9) a+=s[i];
35             else if(s[i] >= A && s[i] <= Z && s[i] != Q && s[i] != Z)
36                 a+= num[s[i]];
37             if(a.length() == 3) a+=-;
38         }
39         if(a.length() == 8)
40         {
41             mp[a]++;
42             if(mp[a] == 2) ans.push_back(a);
43         }
44     }
45     sort(ans.begin(), ans.end());
46     if(ans.size() == 0)
47     {
48         cout<<"No duplicates."<<endl;
49     }
50     else
51     {
52         for (int i = 0; i < ans.size(); i++){
53             cout<<ans[i]<<" "<<mp[ans[i]]<<endl;
54         }        
55     }
56 }

 

POJ 1002 - 487-3279 STL

标签:

原文地址:http://www.cnblogs.com/nicetomeetu/p/5767910.html

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