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

改了n遍仍旧超时。纯C写的我已经尽力了,要是有哪位大佬会优化劳烦告知。样例跑的结果是对的。

Posted by 2017301530052 at 2019-09-18 21:29:40 on Problem 1002
#include <stdio.h>
#include <stdlib.h>
#define Max 60
#define Many 100000
int A[Many];
int id=0; 
void translate(char str[]);
void print();
void insert(int s,int t);
int partition(int s,int t);

int main()
{
	int number;
	char str[Max];
	scanf("%d",&number);
	while(number!=0)
	{
		scanf("%s",str);
		translate(str);
		number--; 
	}
	insert(0,id-1);//快排 
	print(); 
	return 0;
}
void translate(char str[])
{
	int i;
	int sum=0;
	
	for(i=0;str[i]!='\0';i++)
	{
			switch (str[i])
		{
			case 'A':case 'B':case 'C':sum=sum*10+2;break;
			case 'D':case 'E':case 'F':sum=sum*10+3;break;
			case 'G':case 'H':case 'I':sum=sum*10+4;break;
			case 'J':case 'K':case 'L':sum=sum*10+5;break;
			case 'M':case 'N':case 'O':sum=sum*10+6;break;
			case 'P':case 'R':case 'S':sum=sum*10+7;break;
			case 'T':case 'U':case 'V':sum=sum*10+8;break;
			case 'W':case 'X':case 'Y':sum=sum*10+9;break;
			case '0':sum=sum*10;break;
			case '1':sum=sum*10+1;break;
			case '2':sum=sum*10+2;break;
			case '3':sum=sum*10+3;break;
			case '4':sum=sum*10+4;break;
			case '5':sum=sum*10+5;break;
			case '6':sum=sum*10+6;break;
			case '7':sum=sum*10+7;break;
			case '8':sum=sum*10+8;break;
			case '9':sum=sum*10+9;break;
			case '-':break;
			default :return;	
		}
	}
	if(A[id]<10000000)
	{
		A[id]=sum;
		id++;
	}
} 
void insert(int s,int t)
{
	int i;
	if(s<t)
	{
		i=partition(s,t);
		insert(s,i-1);
		insert(i+1,t);
	}
} 
int partition(int s,int t)
{
	int i=s,j=t,x;
	int tmp=A[i];;	
	while(i<j)
	{
		while(j>i&&tmp<=A[j])
			j--;
		A[i]=A[j];
		while(i<j&&tmp>=A[i])
			i++;
		A[j]=A[i];	 
	}
	A[i]=tmp;
	return i;
}

void print()
{
	int i=0,j,m,n,signal=0;
	while(i<id)
	{
		j=1;
		if(A[i]-A[i+1]==0) 
		{
			while(A[i]==A[i+j])
				j++;
			m=A[i]/10000;
			n=A[i]%10000;
			//rintf("m=%d n=%d\n",m,n); 
			if(m<10)
				printf("00");
			else if(m<100)
				printf("0");
			else;
			printf("%d%c",m,'-');
			if(n<10)
				printf("000");
			else if(n<100)
				printf("00");
			else if(n<1000)
				printf("0");
			else;
			printf("%d %d\n",n,j);
			signal=1;
		}	
		i+=j;
	}	
	if(signal==0)
		printf("No duplicates.");
}

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