#include<iostream>
#include <algorithm>
#include<cmath>
using namespace std;
//快速幂
long long qpow(long long x, long long base) {
long long ans = 1;
while (base) {
if (base & 1) {//如果最后一位为1
ans *= x;
}
x = x * x;//不用else 都要执行的
base >>= 1;//记得有赋值操作
}
return ans;
}
//求位数
int logg(int x) {
int t = 0;
while (x) {
++t;
x = x / 10
//x=x >> 1;这个是除以2啊我晕
}
return t;
}
int main() {
int t, x1, x2;
long long p1, p2;
cin >> t;
while (t--) {
cin >> x1 >> p1 >> x2 >> p2;
//先是比较总共的位数
if (logg(x1) + p1 > logg(x2) + p2)
cout << ">" << endl;
else if (logg(x1) + p1 < logg(x2) + p2)
cout << "<" << endl;
else {
//位数相同 从后面0的差值算出具体数值大小再比较
if (p1 - p2 < 0) {
if(qpow(10,p2 - p1)*x2-x1 < 0)
cout << ">" << endl;
else if(qpow(10, p2 - p1)*x2 - x1 == 0)
cout << "=" << endl;
else
cout << "<" << endl;
}
else if (p1 - p2 > 0) {
if (qpow(10, p1 - p2)*x1 - x2 < 0)
cout << "<" << endl;
else if (qpow(10, p1 - p2)*x1 - x2 == 0)
cout << "=" << endl;
else
cout << ">" << endl;
}
else {
if(x1<x2)
cout << "<" << endl;
else if (x1 - x2 == 0)
cout << "=" << endl;
else
cout << ">" << endl;
}
}
}
}
接下来为补题:
B题参考自大佬2
#include<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
//使cin和cout不缓存,速度和scanf printf 差不多
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t, n, * a, min;
cin >> t;
while (t--) {
cin >> n;
a = new int[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a, a+n);
min = a[0];
for (int i = 1; i < n/2+1; ++i) {
//来自于大佬2:
//对最小值进行取模后的结果一定会比最小值要小,因此该数字一定不存在于数组中。
cout << a[i] << " "<<min << endl;
}
}
}