superman

聚精会神搞建设 一心一意谋发展
posts - 190, comments - 17, trackbacks - 0, articles - 0
   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

ZOJ 1159 - 487-3279

Posted on 2008-04-12 21:44 superman 阅读(268) 评论(0)  编辑 收藏 引用 所属分类: ZOJ
 1 /* Accepted 1159 C++ 00:04.20 3584K */
 2 #include <stdio.h>
 3 #include <ctype.h>
 4 #include <string.h>
 5 #include <stdlib.h>
 6 
 7 struct string
 8 {
 9     int size;
10     char str[10];
11     
12     string() { size = 0; }
13     void clear() { size = 0; }
14     void operator += (const char & c)
15     {
16         str[size] = c;
17         size++;
18     }
19     bool operator == (const string & s)
20     {
21         return strcmp(str, s.str) == 0;
22     }
23 }s[100000];
24 
25 int cmp(const void * a, const void * b)
26 {
27     string * c = (string *) a;
28     string * d = (string *) b;
29     return strcmp(c -> str, d -> str);
30 }
31 
32 int main()
33 {
34     int N;
35     scanf("%d"&N);
36     
37     char cur[1000], letter2digit[] = "2223334445556667-77888999-";
38     
39     while(N--)
40     {
41         int n;
42         scanf("%d"&n);
43         for(int i = 0; i < n; i++)
44         {
45             s[i].clear();
46             scanf("%s", cur);
47             for(int j = 0; j < strlen(cur); j++)
48             {
49                 if(s[i].size == 3)
50                     s[i] += '-';
51                 if(cur[j] == '-')
52                     continue;
53                 if(isdigit(cur[j]))
54                 {
55                     s[i] += cur[j];
56                     continue;
57                 }
58                 s[i] += letter2digit[cur[j] - 'A'];
59             }
60         }
61         
62         qsort(s, n, sizeof(string), cmp);
63         
64         int i = 0, cnt = 0;
65         while(i < n)
66         {
67             int j = i + 1;
68             while(j < n && s[i] == s[j])
69                 j++;
70             
71             if(j - i > 1)
72             {
73                 cnt++;
74                 printf("%s %d\n", s[i].str, j - i);
75             }
76             
77             i = j;
78         }
79         if(cnt == 0)
80             printf("No duplicates.\n");
81         
82         if(N)
83             putchar('\n');
84     }
85     
86     return 0;
87 }
88 

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理