题目:http://icpc.njust.edu.cn/Problem/Pku/1002/
AC代码(C++):
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <iomanip>
#include <string.h>
#include <map>
using namespace std;
int cmp(int a, int b) {
return a < b;
}
int main(void) {
int n, cn = 0;
char tel[100];
map<int, int> mm;
cin >> n;
for (int i = 0; i < n; i++) {
int rs = 0;
cin >> tel;
for (int j = 0; tel[j] != '\0'; j++) {
if (tel[j] >= '0'&&tel[j] <= '9')rs = rs * 10 + tel[j] - '0';
else if (tel[j] >= 'A'&&tel[j] <= 'C')rs = rs * 10 + 2;
else if (tel[j] >= 'D'&&tel[j] <= 'F')rs = rs * 10 + 3;
else if (tel[j] >= 'G'&&tel[j] <= 'I')rs = rs * 10 + 4;
else if (tel[j] >= 'J'&&tel[j] <= 'L')rs = rs * 10 + 5;
else if (tel[j] >= 'M'&&tel[j] <= 'O')rs = rs * 10 + 6;
else if (tel[j] >= 'P'&&tel[j] <= 'S'&&tel[j] != 'Q')rs = rs * 10 + 7;
else if (tel[j] >= 'T'&&tel[j] <= 'V')rs = rs * 10 + 8;
else if (tel[j] >= 'W'&&tel[j] <= 'Y')rs = rs * 10 + 9;
}
cn++;
mm[rs]++;
}
bool flag = false;
for (map<int, int>::iterator it = mm.begin(); it != mm.end(); it++) {
if (it->second > 1) {
cout << setw(3) << setfill('0') << it->first / 10000 << '-' << setw(4) << setfill('0') << it->first % 10000 << ' ' << it->second << endl;
flag = true;
}
}
if (flag == false)cout << "No duplicates." << endl;
//system("pause");
}
总结:1.如果号码是1则输出000-0001,即要补零
2.不用map就WA系列...(至少我是这样)