Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
请帮忙看一下~ 在下初学高精这是俺的破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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator