結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

string s;
int n;

inline void Solve() {
    cin >> s;
    n = s.size();
    int state = 1;
    for (int i = 0; i < n; i ++) {
        if (s[i] == '-') {
            state = -1;
            continue;
        }
        if (s[i] == '+') {
            state = 1;
            continue;
        }
        if (s[i] != '?') {
            state = max(state, 0);
            continue;
        } else {
            if (state == -1) {
                s[i] = '1';
                state = 0;
            } else if (state == 0) {
                if (i + 1 < n && (s[i+1] != '+' && s[i+1] != '-')) {
                    s[i] = '+';
                    state = 1;
                } else {
                    s[i] = '1';
                }
            } else {
                s[i] = '9';
            }
        }
    }
    cout << s << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    for (;T--;)
        Solve();
    return 0;
}
0