| ||||||||||
| 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 | |||||||||
哪位大哥帮忙看下,总是超时(g++)#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
int phone_count[100001]={0};
int num[25] = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,0,7,7,8,8,8,9,9,9};
int transfer(string phoneStr);
int main()
{
int N,i,j;
string phoneStr;
bool flag = true;
cin >> N;
for(i=0;i<N;i++)
{
cin >> phoneStr;
int phoneNum = transfer(phoneStr);
phone_count[i] = phoneNum;
}
sort(phone_count,phone_count+N);
i=0;
for(j=0;j<N;++j)
{
if(phone_count[i] != phone_count[j])
{
if(j-i >= 2)
{
flag = false;
printf("%03d-%04d %d\n",phone_count[i]/10000,phone_count[i]%10000,j-i);
}
i=j;
}
}
if(j - i >=2)
{
flag = false;
printf("%03d-%04d %d\n",phone_count[i]/10000,phone_count[i]%10000,j-i);
}
if(flag)cout << "No duplicates." << endl;
return 0;
}
int transfer(string phoneStr)
{
int result = 0;
int i,k=0;
int len = phoneStr.size();
for(i=0;i<len&&k!=7;i++)
{
if('0'<=phoneStr[i] && phoneStr[i] <= '9')
{
result =result*10+(phoneStr[i]-'0');
k++;
}
else if('A'<=phoneStr[i] && phoneStr[i] < 'Z')
{
result=result*10 + num[phoneStr[i]-'A'];
k++;
}
}
return result;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator