Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

小弟总是TLE,谁来帮帮看下怎么改?

Posted by lizongti at 2008-07-28 14:47:49 on Problem 1002
#include <iostream>
#include <string>
#include <deque>
#include <map>
#include <iterator>

using namespace std;
string normalize(string);
string formal(string);
int NumOfData;

int main()
{
	deque<string> CodeList;
	cin>>NumOfData;
	string NewCode;
	int times=NumOfData;
	map<string, int> mymap;
	while(times--)
	{
		cin>>NewCode;
		CodeList.insert(CodeList.end(),normalize(NewCode));
	}
	for(int i=0;i<NumOfData;i++)
	{
		if(mymap.find(CodeList[i]) != mymap.end())
		{
			mymap[CodeList[i]]++;
		}
		else
		{
			mymap[CodeList[i]]=1;
		}
	}
	int ifdupl=0;
	map<string,int>::iterator it;   
	for(it=mymap.begin();it!=mymap.end();++it) 
	{
		if(it->second>1)
		{
			cout<<formal(it->first)<<" "<<it->second<<endl;
			it->second=1;
			ifdupl=1;
		}
	}		
	if(ifdupl==0)
	{
		cout<<"No duplicates."<<endl;
	}	
	return 0;
}

string normalize(string OneCode)
{
	for(unsigned int i=0;i<OneCode.length();i++)
	{
		if(OneCode[i]=='A'||OneCode[i]=='B'||OneCode[i]=='C')
			OneCode[i]='2';
		else if(OneCode[i]=='D'||OneCode[i]=='E'||OneCode[i]=='F')
			OneCode[i]='3';
		else if(OneCode[i]=='G'||OneCode[i]=='H'||OneCode[i]=='I')
			OneCode[i]='4';
		else if(OneCode[i]=='J'||OneCode[i]=='K'||OneCode[i]=='L')
			OneCode[i]='5';
		else if(OneCode[i]=='M'||OneCode[i]=='N'||OneCode[i]=='O')
			OneCode[i]='6';
		else if(OneCode[i]=='P'||OneCode[i]=='R'||OneCode[i]=='S')
			OneCode[i]='7';
		else if(OneCode[i]=='T'||OneCode[i]=='U'||OneCode[i]=='V')
			OneCode[i]='8';
		else if(OneCode[i]=='W'||OneCode[i]=='X'||OneCode[i]=='Y')
			OneCode[i]='9';
		else if(OneCode[i]=='-'||OneCode[i]=='Q'||OneCode[i]=='Z')
		{
			OneCode.erase(i,1);
			i--;
		}
	}
	return OneCode;
}
string formal(string sent)
{
	sent.insert(3,"-");
	return sent;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator