首页 > 代码库 > POJ 1002

POJ 1002

 1 #include <cstdio>
 2 #include <cstring>
 3 
 4 #define t(x) (((x) >= ‘0‘ && (x) <= ‘9‘)? ((x)-‘0‘) : ((x)<‘Q‘?(((x)-‘A‘)/3+2): (((x)==‘R‘||(x)==‘S‘)?7:((x)-‘T‘)/3+8) ))
 5 const std::size_t size = 10000000u;
 6 const std::size_t bytes_size = sizeof(unsigned int) * size;
 7 
 8 int main()
 9 {
10     unsigned int * arr = new unsigned int[size];
11     memset(arr, 0, bytes_size);
12     char s[300];
13     std::size_t num, tmp;
14     scanf("%lu", &num);
15     for (std::size_t i = 0u; i < num; ++i) {
16         scanf("%s", s);
17         tmp = 0;
18         for (std::size_t j = 0u; j < 300u && s[j] != \0; ++j) {
19             if (s[j] == -)
20                 continue;
21 
22             tmp *= 10u;
23             tmp += t(s[j]);
24         }
25         ++(arr[tmp]);
26     }
27 
28     bool not_found = true;
29     for (std::size_t i = 0u; i < size; ++i)
30         if (arr[i] != 0u && arr[i] != 1u) {
31             not_found = false;
32             printf("%03u-%04u %u\n", i / 10000u, i % 10000u, arr[i]);
33         }
34 
35     if (not_found)
36         printf("No duplicates.\n");
37 
38     return 0;
39 }

 

POJ 1002