| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么我的结果是正确的却老是说答案错误呢?是格式问题吗?这是源码,是用hash做的,也不知道会不会超时
#include <iostream>
#include <string>
using namespace std;
int hash[10000000]={0};
/* A, B, and C map to 2
D, E, and F map to 3
G, H, and I map to 4
J, K, and L map to 5
M, N, and O map to 6
P, R, and S map to 7
T, U, and V map to 8
W, X, and Y map to 9 */
int HashMap(string temp)
{
int num=0;
int xxx;
for(int i=0;i<(int)temp.size();i++)
{
switch(temp[i])
{
case 'A':
case 'B':
case 'C':xxx=2;break;
case 'D':
case 'E':
case 'F':xxx=3;break;
case 'H':
case 'I':
case 'G':xxx=4;break;
case 'J':
case 'K':
case 'L':xxx=5;break;
case 'M':
case 'N':
case 'O':xxx=6;break;
case 'P':
case 'R':
case 'S':xxx=7;break;
case 'T':
case 'U':
case 'V':xxx=8;break;
case 'W':
case 'X':
case 'Y':xxx=9;break;
case '-':xxx=-1;break;
default:xxx=temp[i]-'0';
}
if(xxx>=0)
num=num*10+xxx;
}
return num;
}
int main()
{
int times;
cin>>times;
string temp;
int cur;
int high;
int low;
int i;
bool flag=false;
for(i=0;i<times;i++)
{
cin>>temp;
cur=HashMap(temp);
hash[cur]++;
}
for(i=0;i<10000000;i++)
{
if(hash[i]>1)
{
flag=true;
high=i/10000;
low=i-high*10000;
cout<<high<<'-'<<low<<" "<<hash[i]<<endl;
}
}
if(!flag)
cout<<"No duplicates."<<endl;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator