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 90401417 at 2004-12-21 21:22:28 on Problem 1002
#include<stdio.h>
#include<malloc.h>
void main () {
	struct dn{
		int n[7];
		int r;
	};
	struct dn *p;
	int n,i,j,k,s,total;
	char w;
	scanf("%d",&n);
	p=(struct dn *)malloc(sizeof(dn)*n);
	for(j=0;j<n;j++){
		for(i=0;i<7;){
			scanf("%c",&w);
			if(((int)w<=57&&(int)w>=48)||((int)w>=65&&(int)w<=91)){
				if(w=='A'||w=='B'||w=='C') w=2;
				if(w=='D'||w=='E'||w=='F') w=3;
				if(w=='G'||w=='H'||w=='I') w=4;
				if(w=='J'||w=='K'||w=='L') w=5;
				if(w=='M'||w=='N'||w=='O') w=6;
				if(w=='P'||w=='R'||w=='S') w=7;
				if(w=='T'||w=='U'||w=='V') w=8;
				if(w=='W'||w=='X'||w=='Y') w=9;
				if((int)w<=57&&(int)w>=48) w=(int)w-48;
				(p+j)->n[i]=w;
				(p+j)->r=0;
				i++;
			}
		}
	}
	for(j=0;j<n;j++){
		if((p+j)->r==1) continue;
		for(i=0;i<n;i++){
			s=0;
			for(k=0;k<7;k++){
				if((p+j)->n[k]==(p+i)->n[k]) s++;
			}
			if(s==7){
				((p+j)->r)++;
				(p+i)->r=1;
			}
		}
	}
	for(j=0;j<+9;j++){
		for(i=0;i<n;i++){
			if(((p+i)->n[0]==j)&&(p+i)->r>1){
				printf("%d%d%d-%d%d%d%d %d\n",(p+i)->n[0],(p+i)->n[1],(p+i)->n[2],(p+i)->n[3],(p+i)->n[4],(p+i)->n[5],(p+i)->n[6],(p+i)->r);
				total++;
			}
		}
	}
	if(total==0) printf("No duplicates.\n");
}

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