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

怎么就超时了呢??

Posted by xddx at 2011-05-30 20:33:34 on Problem 1002
#include<iostream>
#include<cstring>
#include<string>
int main()
{
	struct phone
	{	
		std::string vv;
		int ntime;
	};
	int n,time=0;
	void dosomething(char &chr);
	std::cin>>n;
	std::string *v=new std::string [n];
	struct phone *vvv=new struct phone [n];
	for(int i=0;i<n;i++){
		std::cin>>v[i];
		int k;
		for(k=0;v[i].begin()+k<v[i].end();){
			if(*(v[i].begin()+k)=='-')
				v[i].erase(v[i].begin()+k);
			else{
				if(*(v[i].begin()+k)<'0' || *(v[i].begin()+k)>'9')
					dosomething(*(v[i].begin()+k));
				k++;
			}
		}
		int j;
		for(j=0;j<time;j++){
			if(vvv[j].vv==v[i]){
				vvv[j].ntime++;
				break;
			}
		}
		if(time==j){
			vvv[time].vv=v[i];
			vvv[time].ntime=1;
			time++;
		}
	}
	int k1,i1,i2;
	for(i1=0;i1<time;i1++){
		k1=i1;
		for(i2=i1;i2<time;i2++)
			if(vvv[k1].vv>vvv[i2].vv)
				k1=i2;
			if(k1!=i1){
				struct phone temp;
				temp.vv=vvv[k1].vv;
				temp.ntime=vvv[k1].ntime;
				vvv[k1].vv=vvv[i1].vv;
				vvv[k1].ntime=vvv[i1].ntime;
				vvv[i1].vv=temp.vv;
				vvv[i1].ntime=temp.ntime;
			}
	}
	bool flag=false;
	for(k1=0;k1<time;k1++){
		if(vvv[k1].ntime!=1){
			int i3;
			for(i3=0;i3<8;i3++){
				if(i3<3)
					std::cout<<vvv[k1].vv[i3];
				else
					if(i3==3)
						std::cout<<"-";
					else
						std::cout<<vvv[k1].vv[i3-1];
			}
			std::cout<<" "<<vvv[k1].ntime<<std::endl;
			flag=true;
		}
	}
	if(!flag)
		std::cout<<"No duplicates."<<std::endl;
	delete [] v;
	delete [] vvv;
	return 0;
}
void dosomething(char &chr)
{
	char a[8][4]={"ABC","DEF","GHI","JKL","MNO","PRS","TUV","XYW"};
	int i=0;
	for(i=0;i<8;i++)
		if(strchr(a[i],chr)){
			chr=i+50;
			return;
		}
}

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