POJ 1002 电话译码问题

这道题目还不算特别难,刚开始不是很明白提交通过率为什么仅有17%,写了一遍,才知道大家可能都被细节给跪了。整个写的还算比较快,1个小时写成,开始测试,各种数据觉得都没问题,但就是一只WA,在调试了好久也都不知道问题出现在哪,最后细读了一遍题目,也 一无所获,最后的最后就瞎搞,上网各种搜索,无意中发现题目中“没有重复的,就输出 No duplicates.”大家要注意到,no duplicates 后面还有个小点,我一开始就是少写了这么个点,跪了好几个小时啊,最后改过来,AC了,细节啊细节啊,再一次证明POJ上的测试真的非常严格。
#include <string>
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>

using  namespace   std;
int  decode(string &source,string &target);

int main(void)
{
	unsigned int      N;
	string   str_temp;
	map<string,int>  ma;
	map<string,int>::iterator cur;
	unsigned int i;

	cin >> N;
	for(i= 0;i<N;i++)
	{	
		cin >> str_temp;
		string  str("00000000");
		if(!decode(str_temp,str))
		{
			++ma[str];
		}
	}

	int   number = 0;
	for(cur = ma.begin();cur !=ma.end();cur++)
	{

		if(cur->second >1)
		{	
			cout <<(*cur).first;		
			cout <<' '<<cur->second <<endl;
			number++;
		}
	}
	if(number == 0)
		cout <<"No duplicates."<<endl;
	return 0;
}

int  decode(string &source,string &target)
{
	int  i,j;
	j  = 0;
	string     str2("00000000");
	for(i = 0;i<source.size();i++)
	{
		if(j == 3)
			target[j++] ='-';
		if(j>8)
			return 0;
		switch(source[i])
		{
			case '0':target[j++] = '0';break;
			case '1':target[j++] = '1';break;
			case '2':
			case 'A':
			case 'B':
			case 'C':  target[j++] = '2';break;
			case '3':
			case 'D':
			case 'E':
			case 'F':  target[j++] = '3';break;
			case '4':
			case 'G':
			case 'H':
			case 'I':  target[j++] = '4';break;
			case '5':
			case 'J':
			case 'K':
			case 'L':  target[j++] = '5';break;
			case '6':
			case 'M':
			case 'N':
			case 'O':  target[j++] = '6';break;
			case '7':
			case 'P':
			case 'R':
			case 'S':  target[j++] = '7';break;
			case '8':
			case 'T':
			case 'U':
			case 'V':  target[j++] = '8';break;
			case '9':
			case 'W':
			case 'X':
			case 'Y':  target[j++] = '9';break;
			default:break;
			}		
	}
	if(j ==8)
		return 0;        //the right input
	else
		return 1;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值