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

so easy....

Posted by blank_bird at 2011-03-02 21:54:56 on Problem 3982
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define N 100
int a[N]={0},b[N]={0},c[N]={0};
void big_add(int *a,int *b)//two big number add ,result in a_array.
{
	int n,m;
	int i,j,k;
	i=N-1;
	while(a[i]==0)i--;
	n=i;
	i=N-1;
	while(b[i]==0)i--;
	m=i;
	n=n>m?n:m;
	for(i=0;i<=n;i++)
	{
		a[i]+=b[i];
		k=i;
		while(a[k]>9)
		{
			a[k+1]++;
			a[k]%=10;
			k++;
		}
	}
}
void To_num(int n,int *a)
{

	int i=-1;
	while(n!=0)
	{
		a[++i]=n%10;
		n/=10;
	}

}
void swap(int *a,int *b)
{
	int i=N-1;
	for(;i>=0;i--)
		b[i]=a[i];
}
int main(void)
{
	int A,B,C;
	int i;
	int d[N];
	while(scanf("%d%d%d",&A,&B,&C)!=EOF)
	{
	To_num(A,a);//把A按位存入数组
	To_num(B,b);
	To_num(C,c);
	for(i=3;i<=99;i++)
	{
		swap(c,d);//d=c;
		big_add(c,b);//c+=b;
		big_add(c,a);//c+=a;
		swap(b,a);//a=b;
		swap(d,b);//b=d;
	}
	//big_add(c,a);
	i=N-1;
	while(c[i]==0)i--;
	for(;i>=0;i--)
		printf("%d",c[i]);
	printf("\n");
	for(i=0;i<N;i++)
	{
		a[i]=b[i]=c[i]=0;
	}
	}//while
	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