fork download
  1. #include <bits/stdc++.h>
  2. #define endl "\n"
  3. using namespace std;
  4. typedef long long ll;
  5. const int mod = 1e9 + 7;
  6.  
  7. string solve(string s1, string s2){
  8. int len = max(s1.size(), s2.size());
  9. while(s1.size() != len) s1 = "0" + s1;
  10. while(s2.size() != len) s2 = "0" + s2;
  11. if(s2 > s1) swap(s1,s2);
  12. int nho = 0;
  13. string tmp = "";
  14. for(int i = s1.size()-1; i >= 0; i--){
  15. int x = (s1[i] - '0') - (s2[i] - '0') - nho;
  16. if(x < 0){
  17. x += 10;
  18. nho = 1;
  19. }
  20. else{
  21. nho = 0;
  22. }
  23. tmp = to_string(x) + tmp;
  24. }
  25. return tmp;
  26. }
  27.  
  28. int main(){
  29. int t;
  30. cin >> t;
  31. while(t--){
  32. string s1, s2;
  33. cin >> s1 >> s2;
  34. cout << solve(s1,s2) << endl;
  35. }
  36. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout