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

tine limited probelm, help me,thank you!

Posted by Gott331 at 2006-04-11 19:24:29 on Problem 1002
hi,i just want to know why my code is so slow.
and can not pass time limited.
thank you.

my code is below:

#include <iostream>
#include <string>
#include <vector>
#include <set>

using namespace std;
int main(){

	int num,i,j=0;
	char reader;
	
	set<string> container;
	vector<string> total;
	string s;
	s.reserve(8);
	int* ruler;
	cin>>num;
	ruler=new int(num);
	for(i=0;i<num;++i){
		
		while(j<7&&cin>>reader){
			
			if(reader!='-'){
				++j;
				switch(reader) {
				case 'A':reader='2';break;
				case 'B':reader='2';break;
				case 'C':reader='2';break;
				case 'D':reader='3';break;
				case 'E':reader='3';break;
				case 'F':reader='3';break;
				case 'G':reader='4';break;
				case 'H':reader='4';break;
				case 'I':reader='4';break;
				case 'J':reader='5';break;
				case 'K':reader='5';break;
				case 'L':reader='5';break;
				case 'M':reader='6';break;
				case 'N':reader='6';break;
				case 'O':reader='6';break;
				case 'P':reader='7';break;
				case 'R':reader='7';break;
				case 'S':reader='7';break;
				case 'T':reader='8';break;
				case 'U':reader='8';break;
				case 'V':reader='8';break;
				case 'W':reader='9';break;
				case 'X':reader='9';break;
				case 'Y':reader='9';break;
				default:;
				}
				if(j==4){
					s=s+"-";
				}
				s=s+reader;	
			}
		
		}
		j=0;
		container.insert(s);
		total.push_back(s);
		
		s.erase(s.begin(),s.end());
	}
	
	set<string>::const_iterator coll;
	for(coll=container.begin();coll!=container.end();++coll){
		int k=0;
		vector<string>::const_iterator collv;
		for(collv=total.begin();collv!=total.end();++collv){
			if(*coll==*collv){
				++k;
			}
		}
		if(k>1){
			cout<<*coll<<' '<<k<<endl;
		}
	}
	return 1;
}

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