1613A - Long Comparison - CodeForces Solution


implementation math *900

Please click on ads to support us..

Python Code:

z = int(input())
def func():
    x1, p1 = map(int, input().split())
    x2, p2 = map(int, input().split())
    mn = min(p1,p2)
    p1-=mn
    p2-=mn
    if p1>=7:
        print(">")
    elif p2>=7:
        print("<")
    else:
        x1=x1*(10**p1)
        x2=x2*(10**p2)
        if x1<x2:
            print("<")
        elif x1>x2:
            print(">")
        else:
            print("=")
    
for i in range(z):
    func()

C++ Code:

// #include<bits/stdc++.h>
// using namespace std;
// int main(){
// ios_base::sync_with_stdio(false);
//  cin.tie(NULL);

// int t;
// cin>>t;
// while(t--){
// int a,c;
// int b,d;
// cin>>a>>c>>b>>d;

// for(int i=0;i<c;i++){
//     a=a*10;
// }
// for(int i=0;i<d;i++){
//     b=b*10;
// }

// if(a>b){
//     cout<<">"<<endl;
// }
// else if(a<b){
//    cout<<"<"<<endl;
// }
// else{
//     cout<<"="<<endl;
// }


// }
// return 0;
// }

#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
 cin.tie(NULL);

int t;
cin>>t;
while(t--){

int a,c;
int b,d;
cin>>a>>c>>b>>d;
int a1=a;
int b1=b;

int a2=0,b2=0;

while(a1){
    a1=a1/10;
    a2++;
}
while(b1){
    b1=b1/10;
    b2++;
}

if((c+a2)!=(d+b2)){
    if((c+a2)>(d+b2)){
        cout<<">"<<endl;
    }
    else{
        cout<<"<"<<endl;
    }
}
else{

   if(max(b2,a2)==a2){

    int y=(a2-b2);
    while(y--){
        b=b*10;
    }

   }
   else{
     int y=(b2-a2);
    while(y--){
        a=a*10;
    }

   }
if(a>b){
    cout<<">"<<endl;
}
else if(a<b){
   cout<<"<"<<endl;
}
else{
    cout<<"="<<endl;
}
   
  
}




}
return 0;
}


Comments

Submit
0 Comments
More Questions

946. Validate Stack Sequences
921. Minimum Add to Make Parentheses Valid
881. Boats to Save People
497. Random Point in Non-overlapping Rectangles
528. Random Pick with Weight
470. Implement Rand10() Using Rand7()
866. Prime Palindrome
1516A - Tit for Tat
622. Design Circular Queue
814. Binary Tree Pruning
791. Custom Sort String
787. Cheapest Flights Within K Stops
779. K-th Symbol in Grammar
701. Insert into a Binary Search Tree
429. N-ary Tree Level Order Traversal
739. Daily Temperatures
647. Palindromic Substrings
583. Delete Operation for Two Strings
518. Coin Change 2
516. Longest Palindromic Subsequence
468. Validate IP Address
450. Delete Node in a BST
445. Add Two Numbers II
442. Find All Duplicates in an Array
437. Path Sum III
436. Find Right Interval
435. Non-overlapping Intervals
406. Queue Reconstruction by Height
380. Insert Delete GetRandom O(1)
332. Reconstruct Itinerary