这道题目还不算特别难,刚开始不是很明白提交通过率为什么仅有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;
}