首页 > 其他 > 详细

10.12-10.18 字符串

时间:2015-10-13 10:32:28      阅读:141      评论:0      收藏:0      [点我收藏+]

//这周做一下字符串的题目,感觉时间越来越不够用==

1.487-3279(简单题)

技术分享
 1 #include <iostream>
 2 #include <string>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <algorithm>
 6 #include <queue>
 7 #include <vector>
 8 #include <set>
 9 #include <map>
10 #include <fstream>
11 #include <cstdlib>
12 #define NDEBUG
13 #include <cassert>
14 
15 using namespace std;
16 
17 #define INF 1000000007
18 #define MIN(a, b) (a > b ? b : a)
19 #define MAX(a, b) (a > b ? a : b)
20 #define MAXN 105
21 
22 int ch[400];
23 char c[50];
24 
25 void init()
26 {
27     ch[A] = ch[B] = ch[C] = 2;
28     ch[D] = ch[E] = ch[F] = 3;
29     ch[G] = ch[H] = ch[I] = 4;
30     ch[J] = ch[K] = ch[L] = 5;
31     ch[M] = ch[N] = ch[O] = 6;
32     ch[P] = ch[R] = ch[S] = 7;
33     ch[T] = ch[U] = ch[V] = 8;
34     ch[W] = ch[X] = ch[Y] = 9;
35 }
36 
37 int main()
38 {
39     int n, flag = 0;
40     init();
41     scanf("%d", &n);
42     getchar();
43     map<int, int> mp;
44     for (int i = 0; i < n; ++i)
45     {
46         gets(c);
47         int tmp = 0;
48         for (int j = 0; j < strlen(c); ++j)
49         {
50             if (c[j] == -) continue;
51             if (c[j] >= A && c[j] <= Z) tmp = tmp*10+ch[c[j]];
52             else if (c[j] >= 0 && c[j] <= 9) tmp = tmp*10 + (c[j]-0);
53         }
54         mp[tmp]++;
55     }
56     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it)
57         if (it->second > 1 ) flag = 1,printf("%03d-%04d %d\n", (it->first)/10000, (it->first)%10000, it->second);
58     if (flag) puts("No duplicates. ");
59     
60     return 0;
61 }
View Code

 

10.12-10.18 字符串

原文:http://www.cnblogs.com/JustForCS/p/4873689.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!