#include <iostream> #include <string.h> #include <stdio.h> using namespace std; int main() { int n , ans = 0; cin >> n ; while(n --) { ans++ ; char a[10000] = {0}, b[10000] ={0} ; int c[10000] ={0}, d[10000] = {0} , e[10000] ={0}; scanf("%s%s" , &a , &b); int len1 = strlen(a) ; int len2 = strlen(b) ; int len = max(len1 , len2); int j = 0 ; for(int i = len1 - 1 ; i >= 0 ; i--) { c[j++] = a[i] - 48 ; } j = 0 ; for(int i = len2 - 1 ; i >= 0 ; i--) { d[j++] = b[i] - 48 ; } int k = 0 ; for(int i = 0 ; i < len ; i++) { e[i] = (c[i] + d[i] + k) % 10 ; k = (c[i] + d[i] + k) / 10 ; } cout << "Case " << ans << ‘:‘ << endl ; printf("%s + %s = " , a , b); if(!k) { for(int i = len - 1 ; i >= 0 ; i--) cout << e[i] ; cout << endl ; } else { e[len] = k ; for(int i = len ; i >= 0 ; i--) cout << e[i] ; cout << endl ; } if(n != 0) printf("\n"); } return 0; }
原文:https://www.cnblogs.com/nonames/p/11185641.html