結果

問題 No.3021 Maximize eval
ユーザー eve__fuyuki
提出日時 2025-02-14 23:57:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 766 bytes
コンパイル時間 1,864 ms
コンパイル使用メモリ 193,236 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-02-14 23:57:33
合計ジャッジ時間 3,014 ms
ジャッジサーバーID
(参考情報)
judge7 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

void fast_io() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
}

void solve() {
	string s;
	cin >> s;
	bool flg = true;
	int n = s.size();
	auto op_ok = [&](int i) {
		if (i == 0 || (s[i - 1] == '+' || s[i - 1] == '-')) return false;
		if (i == n - 1 || (s[i + 1] == '+' || s[i + 1] == '-')) return false;
		return true;
	};
	for (int i = 0; i < n; i++) {
		if (s[i] == '+') {
			flg = true;
			continue;
		}
		if (s[i] == '-') {
			flg = false;
			continue;
		}
		if (s[i] == '?') {
			if (flg) {
				s[i] = '9';
			} else if (op_ok(i)) {
				s[i] = '+';
				flg = true;
			} else {
				s[i] = '1';
			}
		}
	}
	cout << s << "\n";
}
int main() {
	fast_io();
	int t;
	cin >> t;
	for (; t--;) {
		solve();
	}
}
0