結果

問題 No.3308 One-time Changed Formula
コンテスト
ユーザー 👑 loop0919
提出日時 2025-10-24 01:14:00
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 775 bytes
コンパイル時間 766 ms
コンパイル使用メモリ 80,904 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-24 01:17:18
合計ジャッジ時間 1,645 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstdio>

using std::cin;
using std::cout;
using std::string;
using std::ios;

void solve() {
    int N;
    cin >> N;

    string F;
    cin >> F;

    int ans = 0;
    bool is_plus = true;

    for (char f: F) {
        if (f == '+') {
            ans += is_plus ? 9 : 0;
            is_plus = true;
        } else if (f == '-') {
            ans += is_plus ? 9 : 0;
            is_plus = false;
        } else if (f == '*') {
            ans += is_plus ? 9 : 0;
        } else {
            int num = f - '0';
            ans += is_plus ? 9 - num : num - 1;
        }
    }

    cout << ans << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int T;
    cin >> T;

    while (T--) solve();
}
0