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

1002

Posted by yyxxyf at 2007-07-28 16:06:21
可以帮我看一下错哪里了吗?帮帮忙. (错误是runtime_error)
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
int cmp(const void *a,const void *b)
{
	int *first = a;
	int *second = b;
	if (*first > *second)
		return 1;
	else if(*first == *second)
		return 0;
	else
		return -1;
}
int print(int num,int n)
{
	int i;
	for(i=1000000;i>=10000;i /=10)
	{
		printf("%d",num/i);
		num = num%i;
	}
	putchar('-');
	for(i=1000;i>0;i/=10)
	{
		printf("%d",num/i);
		num = num%i;
	}
	printf(" %d\n",n);
	return 0;
}
int main()
{
	int lines;
	int *num;
	int i;
	int n;
	char temp[20];
	int ed;
	scanf("%d",&lines);
	num = (int *)malloc(sizeof(int)*lines);
	n = 0;
	while(lines--)
	{
		num[n] = 0;
		scanf("%s",temp);
		for(i=0;i<20;i++)
		{
			if(temp[i]==0)
				break;
			if(temp[i]=='-')
				continue;
			else
			{
				num[n] *= 10;
				if(temp[i]>='0' && temp[i]<='9')
					num[n] += temp[i]-'0';
				else if(temp[i]<83)
					num[n] += (temp[i]-'A')/3+2;
				else
					num[n] += (temp[i]-'B')/3+2;
				
			}
		}
//		printf("%d\n",num[n]);
		n++;
	}
	lines = n;
	qsort(num,lines,sizeof(int),cmp);
	n=1;
	ed=0;
	for(i=1;i<lines;i++)
	{
		if(num[i] == num[i-1])
			n++;
		else if(n>1)
		{
			ed = 1;
			print(num[i-1],n);
			n = 1;
		}
	}
	if(n>1)
	{
		ed = 1;
		print(num[i-1],n);
	}
	if(!ed)
	{
		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