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

总是RE,最没有提示性的结果,搞不定了,大伙谁给看看

Posted by OOOOOOOO at 2005-12-30 21:44:07 on Problem 1002
#include <stdio.h>
#include <stdlib.h>

#define BUFSIZE 20
#define ERRNUM	10
struct list_item {
	int				 number;
	int				 count;
};
struct list_item list_array[100000];

int list_add_number(int idx,int number);
int list_sort(const void *a,const void *b);
int list_print(int o_count);

int
main()
{
	
	char in_buf[BUFSIZE];
	int in_count,number,o_count=0;
	int i,j,k;
		
	scanf("%d",&in_count);
//	printf("%d\n",in_count);
	

	while(in_count>0) {
		scanf("%s",in_buf);
		--in_count;
		number=0;k=0;
		for(i=0;i<BUFSIZE;++i) {
			switch(in_buf[i]) {
				case 'A':
				case 'B':
				case 'C':
				case '2':
					j=2;break;
				case 'D':
				case 'E':
				case 'F':
				case '3':
					j=3;break;
				case 'G':
				case 'H':
				case 'I':
				case '4':
					j=4;break;
				case 'J':
				case 'K':
				case 'L':
				case '5':
					j=5;break;
				case 'M':
				case 'N':
				case 'O':
				case '6':
					j=6;break;
				case 'P':
				case 'R':
				case 'S':
				case '7':
					j=7;break;
				case 'T':
				case 'U':
				case 'V':
				case '8':
					j=8;break;
				case 'W':
				case 'X':
				case 'Y':
				case '9':
					j=9;break;
				case '1':
					j=1;break;
				case '0':
					j=0;break;
				case '-':
					j=ERRNUM;break;
				default:
					j=ERRNUM;break;
			}
			if(k<7) {
				if((j>=0)&&(j<ERRNUM)) {
					k++;
					number=number*10+j;
				}
			}
			else {
				k=0;
				break;
			}
		}
//		printf("%d\n",o_count);
		o_count+=list_add_number(o_count,number);
//		printf("%d\n",o_count);
	}
//	list_print(o_count);
	//排序,qsort
	qsort(list_array,o_count,sizeof(struct list_item),list_sort);
	list_print(o_count);
	//list_destroy(my_list_head);

	return 0;
}

int list_add_number(int idx,int number)
{	
	int		i;
	int		add_done=0;
//	printf("%d\n",number);
	for(i=0;i<idx;++i) {
		if(number==list_array[i].number) {
			(list_array[i].count)++;
			return 0;
		}
	}
	list_array[i].number=number;
	list_array[i].count=1;
	return 1;
}

int list_sort(const void *a,const void *b)
{
	return (*(struct list_item *)a).number > (*(struct list_item *)b).number ? 1 : -1;
}

int list_print(int o_count)
{
	int i,a,b;
	for(i=0;i<o_count;++i) {
		if(list_array[i].count<=1) continue;
		a=list_array[i].number / 10000;
		b=list_array[i].number % 10000;
		printf("%03d-%04d %d\n",a,b,list_array[i].count);
	}
	if(o_count==0)
		printf("No duplicates.\n");
	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