A. Long Comparison

A. Long Comparison
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

Monocarp wrote down two numbers on a whiteboard. Both numbers follow a specific format: a positive integer x with p zeros appended to its end.

Now Monocarp asks you to compare these two numbers. Can you help him?

Input

The first line contains a single integer t (1t10^4) — the number of testcases.

The first line of each testcase contains two integers x1 and p1 (1x110^6;0p110^6) — the description of the first number.

The second line of each testcase contains two integers x2 and p2 (1x210^6;0p210^6) — the description of the second number.

Output

For each testcase print the result of the comparison of the given two numbers. If the first number is smaller than the second one, print '<'. If the first number is greater than the second one, print '>'. If they are equal, print '='.

Example
input
5
2 1
19 0
10 2
100 1
1999 0
2 3
1 0
1 0
99 0
1 2
output
>
=
<
=
<
Note

The comparisons in the example are: 20>191000=10001999<20001=199<100.

思路:题意是说对比两个数的大小,第二列数是第一列数背后所含有的0的个数,也就是10的次幂。第一个思路是把0补上,也就是把10的次幂乘上,补成一个完整的数来进行比较,相对来说比较麻烦,用到循环算法复杂度较高。所以反其道而行之,我们用10的次幂作为比较单位,如果小于0就说明除数比被除数小,大于0说明除数大于被除数。

题解:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        double x1,p1,x2,p2;
        cin>>x1>>p1>>x2>>p2;
        double ans;
        ans=log10(x1/x2)+p1-p2; //利用10的次幂来进行判断!! 
        //前面的log10的正负可以初步说明x1和x2的大小(但是注意,这是没有算第二列的情况下)
        //然后log10运算处理完后,就相当于此时以10的次幂为单位进行计算了。可以理解一下。
        //然后就可以就把第二列的数据算上,得出最后的大小。
        if(ans==0) cout<<"="<<endl;
        else if(ans>0) cout<<">"<<endl;
        else cout<<"<"<<endl;
    }
}

 

posted @ 2022-01-19 18:42  霜鱼CC  阅读(22)  评论(1)    收藏  举报