题解
2023-08-19 18:45:56
发布于:广东
4阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int cl(int num) {
int maxn = 0;
int minn = 9;
while (num > 0) {
int digit = num % 10;
maxn = max(maxn, digit);
minn = min(minn, digit);
num /= 10;
}
return maxn - minn;
}
int fs(int l, int r) {
int ls = l;
int ml = cl(l);
for (int i = l + 1; i <= r; i++) {
int ln = cl(i);
if (ln > ml) {
ls = i;
ml = ln;
}
if (ml == 9) { // 可以试试去掉这一行,试试就超时
break;
}
}
return ls;
}
int main() {
int T;
cin >> T;
for (int i = 0; i < T; i++) {
int l, r;
cin >> l >> r;
int ship = fs(l, r);
cout << ship << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个