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

请帮忙看一下~ 在下初学高精

Posted by kukumalu at 2006-07-23 19:56:05 on Problem 1503
这是俺的破CODE:
#include <stdio.h>
#include <string.h>
#define MAX 110


void input ( int a[MAX] , char b[MAX] )             //The begining of HP!~   
{
	int k = 0 , HeadPos = 0 , len ;
	len = strlen ( b ) ;                            //"len" is the length of string "b"

	while ( b[HeadPos] == '0' && len != 1 )         //remove leading 0s
		HeadPos ++ ;


	for ( k = 0 ; k < len - HeadPos ; k ++ )        // so , len-HeadPos  is the real length of the number in b
		a[k] = b [len-1-k] - 48  ;                  //now I know that the return value of "strlen" is the "REAL" length of the string , '\0' is excluded ^_^
}




void add ( int a[MAX] , int sum[MAX] )              // HP add     
{
	int i=0 ,carry = 0;                             // " carry" is  carry  ^_^

	for ( ; i < MAX ; i ++ )                                      
	{
		sum[i] = sum[i] + a[i] + carry  ;
		if ( sum[i] > 9 )                           
		{
			carry = 1;
			sum[i] = sum[i] - 10;              
		}
		else carry = 0;
	}
}






int main ()
{
	int j;
	int a[MAX] , sum[MAX] ;
	char b[MAX] ;
	memset ( sum , 0 , sizeof (sum) );
	memset ( a , 0 , sizeof(a) );
	memset (b , '0' , sizeof(b) );

  
	while (1)
	{
		gets(b);
		if ( *b == '0' && b[1] == '\0' )
			break;
		input ( a , b );
		add (a , sum);
	}

	int i = MAX -1 ;
	while ( sum[i]== 0)
	{	-- i; j=i;}
	while ( j >= 0)
	{
		printf ( "%d" , sum[j]);
		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