| ||||||||||
| 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 | |||||||||
Re:我的方法超时了,请帮我分析一下时间复杂度1In Reply To:我的方法超时了,请帮我分析一下时间复杂度1 Posted by:relive_7 at 2005-08-20 17:05:32 //#include <iostream>
#include <string>
#include <map>
#include <fstream>
using namespace std;
ifstream cin("t.in");
ofstream cout("t.out");
map<string,int> ap;
map<char,int> mp;
int main()
{
mp['A']=2;mp['B']=2;mp['C']=2;mp['D']=3;mp['E']=3;mp['F']=3;mp['G']=4;mp['H']=4;
mp['I']=4;mp['J']=5;mp['K']=5;mp['L']=5;mp['M']=6;mp['N']=6;mp['O']=6;mp['P']=7;
mp['R']=7;mp['S']=7;mp['T']=8;mp['U']=8;mp['V']=8;mp['W']=9;mp['X']=9;mp['Y']=9;
int round,num=0,len;
string a,b="00000000";
cin>>round;
while (round>=1)
{
num=0;
cin>>a;
len=a.length();
for (int i=0;i<len;i++)
{
if (a[i]>='A'&&a[i]<='Z')
{
b[num]=mp[a[i]]+'0';
num++;
}
if (a[i]<='9'&&a[i]>='0')
{
b[num]=a[i];
num++;
}
}
b[8]='\0';
++ap[b];
round--;
}
int flag=0;
for (map<string,int>::iterator it=ap.begin(); it != ap.end(); ++it )
{
num=0;
if ((it->second)>1)
{
len=it->first.size();
for (int j=0;j<7;j++)
{
if (num==3) {cout<<"-";num++;j-=1;}
else { cout<<it->first[j];
num++;}
}
cout<<" "<<it->second<<endl;
flag=1;
}
}
if (flag==0)
{
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