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

哪个高手能给看下我的程序,测试0和32767都正确,但是提交老是答案错了

Posted by happyboy1986 at 2010-12-12 10:10:47 on Problem 3982
#include<stdio.h>
#include<string.h>
int a[150]={0};
int b[150]={0};
int c[150]={0};
int d[150]={0};
void bigadd(int a[],int b[],int c[],int d[])
{
	int i,j,k,tmp;
	i=a[0];		//获取a的位数
	j=b[0];		//获取b的位数
	k=c[0];		//获取c的位数
	tmp=(i>j?i:j);
	d[0]=(k>tmp?k:tmp)+1;//设置d的位数
	//printf("%d\n",d[0]);
	for(i=1;i<=d[0];i++)
	{
		d[i]=a[i]+b[i]+c[i];
	}
	//处理进位情况
	for(i=1;i<=d[0];i++)
	{
		d[i+1]+=d[i]/10;
		d[i]=d[i]%10;
	}
}
int  main()
{
	char str[5];
	char str1[5];
	char str2[5];
	int k=0,j=0;
	while(scanf("%s%s%s",str,str1,str2)==3)
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		memset(d,0,sizeof(d));

		

		k=strlen(str);
		a[0]=k;
		//数据的低位放在数组的低地址
		for(j=k;j>=1;j--)
		{
			a[k-j+1]=str[j-1]-'0';
		}
		//memset(str,0,5);
		
		
		k=strlen(str1);
		b[0]=k;
		//数据的低位放在数组的低地址
		for(j=k;j>=1;j--)
		{
			b[k-j+1]=str1[j-1]-'0';
		}
		//memset(str,0,5);
	
		
		k=strlen(str2);
		c[0]=k;
		//数据的低位放在数组的低地址
		for(j=k;j>=1;j--)
		{
			c[k-j+1]=str2[j-1]-'0';
		}
		//bigadd(a,b,c,d);
		for(j=3;j<=99;j++)
		{
			bigadd(a,b,c,d);
			for(k=0;k<=b[0];k++)
				a[k]=b[k];
			for(k=0;k<=c[0];k++)
				b[k]=c[k];
			for(k=0;k<=d[0];k++)
				c[k]=d[k];
			for(k=0;k<=d[0];k++)
				d[k]=0;
		}

		
		
		for(k=c[0];k>=1;k--)
		{	
			if(c[k]!=0)
				break;
		}
		if(k==0)
			printf("%d",k);
		else
		{
			for(j=k;j>=1;j--)
			{
				printf("%d",c[j]);
			}
		}
		printf("\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