#include<iostream> #include<vector> #include<algorithm> #include<iomanip> #include<string> #include<cmath> #include<unordered_map> #include<stack> using namespace std; bool judge(string& a, string& b) { if (a.size() < b.size()) return true; if (a.size() > b.size()) return false; for (int i = 0; i < a.size(); i++) { if (a[i] < b[i]) return true; } return false; } int main() { int T; cin >> T; getchar(); for (int i = 0; i < T; i++) { string a, b; getline(cin, a); getline(cin, b); int flag = 0; if (judge(a, b)) { flag = 1; while (a.size() < b.size()) { a = '0' + a; } } if (flag == 1) swap(a, b); while (b.size() < a.size()) { b = '0' + b; } int pos = a.size() - 1; string res; int jie = 0; while (pos >= 0) { int sub = (a[pos] - '0') - (b[pos] - '0'); if (jie == 1) { sub--; jie = 0; } if (sub < 0) { sub += 10; jie = 1; } res = to_string(sub) + res; pos--; } cout << "Case #" << i + 1 << ":" << endl; if (res[0] == '0') { cout << 0 << endl; continue; } if (flag == 1) cout << '-' << res << endl; else cout << res << endl; } } |
Double click to view unformatted code.