POJ 1002.487-3279

题目: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系列...(至少我是这样)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值