結果

問題 No.193 筒の数式
ユーザー YamaKasaYamaKasa
提出日時 2018-07-31 22:49:31
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,059 bytes
コンパイル時間 3,310 ms
コンパイル使用メモリ 79,724 KB
実行使用メモリ 57,752 KB
最終ジャッジ日時 2023-10-19 20:33:36
合計ジャッジ時間 6,920 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
57,452 KB
testcase_01 AC 135 ms
57,320 KB
testcase_02 AC 136 ms
56,988 KB
testcase_03 AC 136 ms
57,164 KB
testcase_04 AC 134 ms
57,052 KB
testcase_05 AC 134 ms
57,388 KB
testcase_06 AC 133 ms
55,316 KB
testcase_07 AC 134 ms
57,424 KB
testcase_08 AC 137 ms
57,332 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 132 ms
57,052 KB
testcase_12 AC 138 ms
57,124 KB
testcase_13 AC 137 ms
57,020 KB
testcase_14 WA -
testcase_15 AC 138 ms
55,412 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		scan.close();
		int l = S.length();
		String ary[] = S.split("");
		int max = Integer.MIN_VALUE;
		for(int i = 0; i < l; i++) {
			String s = "";
			// 前半部分
			for(int j = i; j < l; j++) {
				s += ary[j];
			}
			// 後半部分
			for(int j = 0; j < i; j++) {
				s += ary[j];
			}
			if(!s.substring(0, 1).matches("[0-9]")) {
				continue;
			}
			if(!s.substring(l - 1, l).matches("[0-9]")) {
				continue;
			}
			Deque<String> queue0 = new ArrayDeque<String>();
			Deque<Integer> queue = new ArrayDeque<Integer>();
			String num = "";
			int t0 = 0;
			int index = 0;
			for(int j = 0; j < l; j++) {
				String t1 = s.substring(j, j + 1);
				if(t1.matches("[0-9]")) {
					num += t1;
				}else {
					queue0.add(t1);
					int num1 = zeroToNum(num);
					num = "";
					queue.add(num1);
					index = j;
				}
			}
			int last = zeroToNum(s.substring(index, l));
			queue.add(last);
//			for(int j : queue) {
//				System.out.print(j + " ");
//			}
//			System.out.println();
//			for(String o : queue0) {
//				System.out.print(o + " ");
//			}
//			System.out.println();
//			//System.out.println(index);
//			System.out.println(s);
			for(String ope : queue0) {
				if(ope.equals("-")) {
					int num1 = queue.pop();
					int num2 = queue.pop();
					t0 = num1 - num2;
					queue.push(t0);
				}else {
					int num1 = queue.pop();
					int num2 = queue.pop();
					t0 = num1 + num2;
					queue.push(t0);
				}
			}
			t0 = queue.pop();
			if(max < t0) {
				max = t0;
			}
		}
		System.out.println(max);
	}
	static int zeroToNum(String s) {
		int l = s.length();
		if(l == 1 || !s.substring(0, 1).equals("0")) {
			return Integer.parseInt(s);
		}else {
			for(int i = 1; i < l; i++) {
				char c = s.charAt(i);
				if(c != 0) {
					String num = s.substring(i, l);
					return Integer.parseInt(num);
				}
			}
			return 0;
		}
	}
}
0