| ||||||||||
| 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 | |||||||||
TLE 求告知哪个部分超时#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
using namespace std;
bool cmp(string a,string b)
{
if(a < b)
{
return true;
}
else
{
return false;
}
}
int main()
{
int number;
cin>>number; // the number of telephone numbers( number <= 100000 )
vector<string> tel; //store the processing telephone numbers
int i;
for(i = 0; i < number; i++) //processing the telephone numbers
{
string strtemp1,strtemp2(7,' ');
cin>>strtemp1;
for(string::size_type j = 0, k = 0; j < strtemp1.size(); ++j)
{
if(strtemp1[j] != '-')
{
if(isalpha(strtemp1[j]))
{
if(strtemp1[j] < 'Q')
{
strtemp1[j] = (strtemp1[j] - 65) / 3 + 50;
}
else
{
strtemp1[j] = (strtemp1[j] - 66) / 3 + 50;
}
}
strtemp2[k++] = strtemp1[j];
}
}
tel.push_back(strtemp2);
}
sort(tel.begin(),tel.end(),cmp);
bool flag = false; //judgment the exist of same numbers
for(int j = 0, k = 1; j < tel.size() - 1; )
{
if(tel[j] != tel[j+1])
{
tel.erase(tel.begin() + j);
}
else
{
if(!flag)
{
flag = true;
}
k++;
for(int x = 2; x < tel.size() - j; ++x)
{
if(tel[j] == tel[j+x])
{
k++;
}
else
{
break;
}
}
for(i = 0; i < 3; i++)
{
cout<<tel[j][i];
}
cout<<"-";
for(i = 3; i < 7; i++)
{
cout<<tel[j][i];
}
cout<<" "<<k<<endl;
j = j + k;
k = 1;
}
}
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