Ray's playground

 

POJ 1002

code
  1 #include <iostream>
  2 #include <map>
  3 #include <string>
  4 using namespace std;
  5 
  6 char mapchar(char c)
  7 {
  8     switch(c)
  9     {
 10         case '0':
 11             return '0';
 12 
 13         case '1':
 14             return '1';
 15 
 16         case '2':
 17         case 'A':
 18         case 'B':
 19         case 'C':
 20             return '2';
 21 
 22         case '3':
 23         case 'D':
 24         case 'E':
 25         case 'F':
 26             return '3';
 27         
 28         case '4':
 29         case 'G':
 30         case 'H':
 31         case 'I':
 32             return '4';
 33 
 34         case '5':
 35         case 'J':
 36         case 'K':
 37         case 'L':
 38             return '5';
 39 
 40         case '6':
 41         case 'M':
 42         case 'N':
 43         case 'O':
 44             return '6';
 45         
 46         case '7':
 47         case 'P':
 48         case 'R':
 49         case 'S':
 50             return '7';
 51         
 52         case '8':
 53         case 'T':
 54         case 'U':
 55         case 'V':
 56             return '8';
 57         
 58         case '9':
 59         case 'W':
 60         case 'X':
 61         case 'Y':
 62             return '9';
 63     }
 64 
 65     return c;
 66 }
 67 
 68 string check(string s)
 69 {
 70     string value = "";
 71     for(string::iterator iterator = s.begin(); iterator != s.end(); iterator++)
 72     {
 73         char c = *iterator;
 74         
 75         c = mapchar(c);
 76         if(c >= '0' && c <= '9')
 77         {
 78             value += c;
 79             if(value.length() == 3)
 80             {
 81                 value += '-';
 82             }
 83         }
 84         else if(c == '-'){}
 85         else
 86         {
 87             return "";
 88         }
 89     }
 90 
 91     return value;
 92 }
 93 
 94 int main()
 95 {
 96     map<stringint> counters;
 97     string s;
 98 
 99     int count = 0;
100     cin >> count;
101 
102     for(int j = 0; j < count; j++)
103     {
104         cin >> s;
105         if(s.length() >= 7)
106         {
107             s = check(s);
108             if(s.length() == 8)
109             {
110                 map<stringint>::iterator iterator = counters.find(s);
111                 if(iterator != counters.end())
112                 {
113                     iterator->second += 1;
114                 }
115                 else
116                 {
117                     counters.insert(pair<stringint>(s, 1));
118                 }
119             }
120         }
121     }
122 
123     bool b = false;
124     for(map<stringint>::iterator i = counters.begin(); i != counters.end(); i++)
125     {
126         if(i->second > 1)
127         {
128             cout << i->first << " " << i->second << endl;
129             b = true;
130         }
131     }
132 
133     if(!b)
134     {
135         cout << "No duplicates.";
136     }
137 }

 

posted on 2010-08-11 22:18  Ray Z  阅读(245)  评论(0编辑  收藏  举报

导航