Description
Input
Output
Sample Input
123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890 0
Sample Output
370370367037037036703703703670
大意:高精度加法
#include<cstdio> #include<cstring> using namespace std; int sum[150]; void add(char *a) { int len = strlen(a); int k = 1; for(int i = len - 1 ;i >= 0;i--){ sum[k] += (a[i] - ‘0‘); sum[k+1] += sum[k]/10; sum[k] %= 10; k++; } } int main() { char a[105][105]; for(int i = 0 ; ; i++){ scanf("%s",a[i]); int n = strlen(a[i]); if(n == 1 && a[i][0] == ‘0‘) break; add(a[i]); } int flag = 0; for(int i = 110; i >= 1 ;i--){ if(sum[i] == 0 && flag == 0) continue; else { flag = 1; printf("%d",sum[i]); } } return 0; }
原文:http://www.cnblogs.com/zero-begin/p/4372688.html