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

各种数据试得都对,就是WA,帮帮忙来看看程序

Posted by jxfzlmb at 2007-12-26 22:40:46 on Problem 1002
#include <stdio.h>
static int m[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,0,7,7,8,8,8,9,9,9,0};
int c,ok,x,y;
long b[5000],a[5000],l,n,q,w,an;

void sort(int l,int r){
	x=l;y=r+1;
	c=(x+y)/2;
	q=a[c];a[c]=a[l];a[l]=q;
	w=b[c];b[c]=b[l];b[l]=w;
	while(1){
		while(a[++x]<=q);
		while(a[--y]>=q);
		if(x<y){
			w=a[x];a[x]=a[y];a[y]=w;
			w=b[x];b[x]=b[y];b[y]=w;
		}
		else{
			a[l]=a[y];a[y]=q;
			w=b[l];b[l]=b[y];b[y]=w;
			if(l==y-2){
				if(a[l]>a[y-1]){
					w=a[l];a[l]=a[y-1];a[y-1]=w;
					w=b[l];b[l]=b[y-1];b[y-1]=w;
				}
			}
			else if(l<y-1)sort(l,y-1);
			if(r==y+2){
				if(a[r]<a[y+1]){
					w=a[r];a[r]=a[y+1];a[y+1]=w;
					w=b[r];b[r]=b[y+1];b[y+1]=w;
				}
			}
			else if(r>y+1)sort(y+1,r);
			break;
		}
	}
}

int main(){
	scanf("%d",&n);scanf("%c",&c);
	an=0;
	for(q=0;q<n;q++){
		l=0;
		while(scanf("%c",&c)&&(c!='\n')){
			if((c>='A')&&(c<='Z'))l=l*10+m[c-'A'];
			else if((c>='a')&&(c<='z'))l=l*10+m[c-'a'];
			else if((c>='0')&&(c<='9'))l=l*10+c-'0';
		}
		for(w=0;w<an;w++){
			if(a[w]==l){b[w]++;break;}
		}
		if(w==an){
			a[w]=l;
			b[w]=1;
			an++;
		}
	}
	q=0;
	for(w=0;w<an;w++){
		if(b[w]!=1){
			a[q]=a[w];
			b[q]=b[w];
			q++;
		}
	}
	an=q;
	if(an==0)printf("No duplicates.");
	else{
		if(an==2){
			if(a[0]>a[1]){
				q=a[1];a[1]=a[0];a[0]=q;
				q=b[1];b[1]=b[0];b[0]=q;
			}
		}
		else if(an>2){
			a[an]=10000000;
			sort(0,an-1);
		}
		for(q=0;q<an;q++)printf("%03d-%04d %d\n",a[q]/10000,a[q]%10000,b[q]);
	}
	return 0;
}

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