标签:int ++i efi 注意 string ase ios return ret
#include <iostream> #include <string> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define SWAP(a,b) auto c=a;a=b;b=c; int main() { int n = 0, c; string a, b, ans; cin >> n; FOR(i, 1, n+1){ cin >> a >> b; cout << "Case " << i << ":" << endl; cout << a << " + " << b << " = "; // << a + b << endl << endl; if (a.size() < b.size()) { SWAP(a,b) } c = 0; ans = ""; FOR(j, 0, b.size()){ char a_num = a[a.size()-1 - j]; char b_num = b[b.size()-1 - j]; int res = a_num + b_num - 2 * ‘0‘ + c; c = res / 10; res %= 10; ans = char(res + ‘0‘) + ans; } FOR(j, b.size(), a.size()){ char a_num = a[a.size()-1 - j]; int res = a_num - ‘0‘ + c; c = res / 10; res %= 10; ans = char(res + ‘0‘) + ans; } cout << ans << endl; if(i != n) cout << endl; } return 0; }
需要注意的是,在最后一个 Case 的输出之后不需要再输出空行。
标签:int ++i efi 注意 string ase ios return ret
原文地址:https://www.cnblogs.com/KakagouLT/p/13048990.html