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 BoGe at 2007-02-06 19:44:02 on Problem 1002
#include<iostream.h>
#include<iomanip.h>
#include<stdlib.h>

int compare(const void * a,const void * b)
{
	return *((int*)a)-*((int*)b);
}

void qsort(int A[],int s, int t)
{
	int i,j;
	int temp;
	if ( s >= t ) return;
	i = s; j = t; temp = A[i];
	while ( i < j ) {
		while ( i < j && temp < A[j] ) j --;
		if ( i < j ) A[i++] = A[j];
		while ( i < j && A[i] <= temp ) i ++;
		if ( i < j ) A[j--] = A[i];
	}
	A[i] = temp;
	qsort(A,s,--j);
	qsort(A,++i,t);
}

void main ()
{
	int i,j,k,num,cal,value=1;	cin>>num;
	char a[100],b[8];
	const char con[]="22233344455566677778889999";
	int * c=new int[num];
	for(i=0;i<num;i++)
	{
		cin>>a;	k=0;
		for(j=0;a[j];j++)
		{
			if(a[j]>='A' && a[j]<='Z')
			{b[k]=con[a[j]-'A'];k++;continue;}
			if(a[j]>='0' && a[j]<='9')
			{b[k]=a[j];k++;}
		}
		c[i]=atoi(b);
	}
	
	qsort(c,0,num-1);
	
	for(i=0;i<num;)
	{
		cal=1;
		for(j=i+1;j<num&&c[j]==c[i];j++) cal++;
		if(cal>1)
		{
			value=0;
			cout<<setfill('0')<<setw(3)<<c[i]/10000<<"-"<<setfill('0')<<setw(4)<<c[i]%10000<<" "<<cal<<endl;//
		}
		i=j;
	}
	if(value)	cout<<"No duplicates."<<endl;
	delete[]c;
}

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