結果

問題 No.3308 One-time Changed Formula
コンテスト
ユーザー さかさのさかな
提出日時 2025-10-25 17:16:27
言語 Java
(openjdk 23)
結果
AC  
実行時間 481 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 7,855 ms
コンパイル使用メモリ 86,452 KB
実行使用メモリ 53,068 KB
最終ジャッジ日時 2025-10-25 17:16:42
合計ジャッジ時間 10,508 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

package no3308_one_time_changed_fomula;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		while(t > 0) {
			int n = sc.nextInt();
			String s = "+";
			s += sc.next();
			s += '+';
			int ind = 0;
			long ans = 0;
			boolean befMinus = false;
			while(ind != n + 1) {
				long num = 0;
				boolean plus = s.charAt(ind) == '+';
				if(ind != 0 && !befMinus)ans += 9;
				ind++;
				while(s.charAt(ind) != '+' && s.charAt(ind) != '-'){
					char c = s.charAt(ind);
					if(c != '*' && plus) {
						num += '9' - c;
					}else if(c != '*' && !plus) {
						num += c - '1';
					}
					else if(plus) {
						num += 9;
					}ind++;
				}ans += num;
				befMinus = !plus;
			}
			sb.append(ans + "\n");
			t--;
		}System.out.print(sb);
	}

}
0