Advertisement
HaciyevAlik

Long comparison

Oct 15th, 2022
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5. using ld = long double;
  6. const int INF = 1e9;
  7.  
  8. //ağ balqabaq boz balqabaq, boz balqabaq ağ balqabaq
  9.  
  10. void solve(){
  11.     ll x1,p1; cin >> x1 >> p1;
  12.     ll x2,p2; cin >> x2 >> p2;
  13.     if(x1 == x2){
  14.         if(p1 == p2) cout << "=";
  15.         else if(p1 > p2) cout << ">";
  16.         else cout << "<";
  17.     } else if(x1 > x2){
  18.         //2 hal ola biler. ölçüləri bərabər
  19.         //ölçüləri fərqli
  20.         //y'in ölçüsü böyük ola bilməz. Çünki x1 > x2
  21.         string s = to_string(x1);
  22.         string ss = to_string(x2);
  23.         ll x = (ll)s.size();
  24.         ll y = (ll)ss.size();
  25.         if(x == y){
  26.             if(p1 >= p2) cout << ">";
  27.             else cout << "<";
  28.             return;
  29.         } else if(x > y){
  30.             ll z = x - y;
  31.             if(p2 - p1 < z){
  32.                 cout << ">";
  33.             } else if(p2 - p1 > z){
  34.                 cout << "<";
  35.             } else {
  36.                 //p2 - p1 == z -> yəni ki, ölçülər bərabər
  37.                 for(ll i = 0;i<(ll)ss.size();++i){
  38.                     char ch = s[i];
  39.                     char chh = ss[i];
  40.                     ll xx = ch - '0';
  41.                     ll yy = chh - '0';
  42.                     if(xx > yy){
  43.                         cout << ">";
  44.                         return;
  45.                     } else if(xx < yy){
  46.                         cout << "<";
  47.                         return;
  48.                     }
  49.                 }
  50.                 cout << "=";
  51.             }
  52.         }
  53.     } else if(x1 < x2){
  54.         string s = to_string(x1);
  55.         string ss = to_string(x2);
  56.         ll x = (ll)s.size();
  57.         ll y = (ll)ss.size();
  58.         if(x == y){
  59.             if(p1 <= p2) cout << "<";
  60.             else cout << ">";
  61.             return;
  62.         } else if(x < y){
  63.             ll z = y - x;
  64.             if(p1 - p2 < z){
  65.                 cout << "<";
  66.             } else if(p1 - p2 > z){
  67.                 cout << ">";
  68.             } else {
  69.                 //p1 - p2 == z
  70.                 for(ll i = 0;i<(ll)s.size();++i){
  71.                     char ch = s[i];
  72.                     char chh = ss[i];
  73.                     ll xx = ch - '0';
  74.                     ll yy = chh - '0';
  75.                     if(xx > yy){
  76.                         cout << ">";
  77.                         return;
  78.                     } else if(xx < yy){
  79.                         cout << "<";
  80.                         return;
  81.                     }
  82.                 }
  83.                 cout << "=";
  84.                 return;
  85.             }
  86.         }
  87.     }
  88. }
  89.  
  90. int main(){
  91.     cin.tie(0) -> sync_with_stdio(0);
  92.     cin.exceptions(cin.failbit);
  93.     //freopen("in.txt","r",stdin);
  94.     //freopen("out.txt","w",stdout);
  95.     int t = 1; cin>>t;
  96.     while(t--){
  97.         solve();
  98.         cout << "\n";
  99.     }
  100.     return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement