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 00746029 at 2008-03-08 13:44:44 on Problem 1002 and last updated at 2008-03-08 13:45:04
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char cdail[100000][30];
int ndail[100000];

int compare(const void * elem1,const void * elem2)
{
	int *p1,*p2;
	p1=(int *)elem1;
	p2=(int *)elem2;
	return *p1-*p2;
}

void transf(int n)
{
	int len,i,j;
	for(i=0;i<n;i++){
		len=strlen(cdail[i]);
		ndail[i]=0;
		for(j=0;j<len;j++){
			switch(cdail[i][j]){
				case '0' : ndail[i]*=10;break;
				case '1' : ndail[i]=ndail[i]*10+1;break;
				case '2' :
				case 'A' :
				case 'B' :
				case 'C' : ndail[i]=ndail[i]*10+2;break;
				case '3' :
				case 'D' :
				case 'E' :
				case 'F' : ndail[i]=ndail[i]*10+3;break;
				case '4' :
				case 'G' :
				case 'H' :
				case 'I' : ndail[i]=ndail[i]*10+4;break;
				case '5' :
				case 'J' :
				case 'K' :
				case 'L' : ndail[i]=ndail[i]*10+5;break;
				case '6' :
				case 'M' :
				case 'N' :
				case 'O' : ndail[i]=ndail[i]*10+6;break;
				case '7' :
				case 'P' :
				case 'R' :
				case 'S' : ndail[i]=ndail[i]*10+7;break;
				case '8' :
				case 'T' :
				case 'U' :
				case 'V' : ndail[i]=ndail[i]*10+8;break;
				case '9' :
				case 'W' :
				case 'X' :
				case 'Y' : ndail[i]=ndail[i]*10+9;break;
			}
		}
	}
}

void main()
{
	int nnums,i,j,w=0;
	scanf("%d",&nnums);
	for(i=0;i<nnums;i++)
		scanf("%s",cdail[i]);
	transf(nnums);
	qsort(ndail,nnums,sizeof(int),compare);
	for(i=0;i<nnums-1;i++){
		if(ndail[i]==ndail[i+1]){
			w=1;
			for(j=2;i+j<nnums;j++)
				if(ndail[i]!=ndail[i+j])
					break;
			printf("%03d-%04d %d\n",ndail[i]/10000,ndail[i]%10000,j);
			i=i+j-1;
		}
	}
	if(!w)
		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