結果

問題 No.3308 One-time Changed Formula
コンテスト
ユーザー forest3
提出日時 2025-10-27 16:17:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 561 bytes
コンパイル時間 1,385 ms
コンパイル使用メモリ 163,344 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-27 16:17:19
合計ジャッジ時間 2,902 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i, a, b) for (int i = a; i < b; i++)
using ll = long long;

int main(){
	int t;
	cin >> t;
	rep(ti, 0, t) {
		int n;
		string s;
		cin >> n >> s;
		int ans = 0, sf = 0;
		rep(i, 0, n) {
			if(isdigit(s[i])) {
				int d = s[i] - '0';
				if(sf) ans += d - 1;
				else ans += 9 - d;
			}
			else if(s[i] == '*') {
				if(sf == 0) ans += 9; 
			}
			else if(s[i] == '-') {
				sf = 1;
				ans += 9;
			}
			else if(s[i] == '+') {
				if(sf == 0) ans += 9;
				sf = 0;
			}
		}
		cout << ans << endl;
	}
}
0