UVa 424 - Integer Inquiry

来源:互联网 发布:淘宝晚班客服在家 编辑:程序博客网 时间:2024/04/28 10:58

题目:大整数加法。

分析:简单题、模拟、大整数。赤果果的大整数加法。(第100题了)。

#include <stdio.h>#include <stdlib.h>#include <string.h>char A[110];int  a[110];int  s[110];int main(){memset( s, 0, sizeof(s) );while ( scanf("%s",&A) && strcmp(A,"0") ) {for ( int i = 0 ; i < 106 ; ++ i )a[i] = 0;int l = strlen(A);for ( int i = 0 ; i < l ; ++ i )a[i] = A[l-1-i]-'0';for ( int i = 0 ; i < 106 ; ++ i )s[i] += a[i];for ( int i = 0 ; i < 106 ; ++ i ) {s[i+1] += s[i]/10;s[i] %= 10;} }int end = 105;while ( end >= 1 && !s[end] ) end --;while ( end >= 0 ) printf("%d",s[end --]);printf("\n");system("pause");return 0;}


原创粉丝点击