1 #include <iostream> 2 #include <string> 3 #include <cstring> 4 using namespace std; 5 int main() 6 { 7 string a,b,tmp; 8 int x[11000] = {},y[11000] = {},z[11000] = {}; 9 int ok = 0; 10 cin >> a >> b; 11 if ((a.length() < b.length()) || ((a.length() == b.length()) && a < b)) 12 { 13 tmp = a; 14 a = b; 15 b = tmp; 16 ok = 1; 17 } 18 for (int i = 0;i < a.length();i++) 19 x[a.length() - i] = a[i] - '0'; 20 for (int i = 0;i < b.length();i++) 21 y[b.length() - i] = b[i] - '0'; 22 int len = 1; 23 while (len <= a.length() || len <= b.length()) 24 { 25 if (x[len] < y[len]) 26 { 27 x[len] = x[len] + 10; 28 x[len + 1] = x[len + 1] - 1; 29 } 30 z[len] = x[len] - y[len]; 31 len++; 32 } 33 while (z[len] == 0 && len >= 1) 34 len--; 35 if (len == 0) 36 len = 1; 37 if (ok == 1) 38 cout << "-"; 39 for (int i = len;i >= 1;i--) 40 cout << z[i]; 41 return 0; 42 }