QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#479#275510#7897. Largest DigityimonyimonFailed.2023-12-05 20:37:052023-12-05 20:37:06

詳細信息

Extra Test:

Invalid Input

input:

1 85 89 185 189

output:


result:

FAIL Expected EOLN (stdin, line 1)

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#275510#7897. Largest DigityimonAC ✓0ms3640kbC++11748b2023-12-04 19:44:412023-12-04 19:44:42

answer

#include<iostream>
#include<set>
#include<algorithm>
#include<map>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
ll a, b, x, y;
ll res = -1;
ll f = 1;
void fun(ll x)
{
	string s = to_string(x);
	ll ans = -1;
	for (ll i = 0; i < s.size(); i++)
	{
		ans = max(ans, (ll)s[i] - '0');
	}
	if (res == 9) {
		cout << res << endl;
		f = 0;
	}
	else res = ans;
}
signed main()
{
	ll t;
	cin >> t;
	while (t--)
	{
		f = 1;
		res = -1;
		cin >> a >> b >> x >> y;
		ll ans = 0;
		for (ll i = a; i <= b; i++)
		{
			for (ll j = x; j <= y; j++)
			{
				ans = i + j;
				fun(ans);
				if (!f) break;
			}
			if (!f) break;
		}
		if (f == 1) cout << res << endl;
	}
}