結果

問題 No.193 筒の数式
ユーザー uafr_csuafr_cs
提出日時 2015-06-09 01:51:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 1,000 ms
コード長 1,295 bytes
コンパイル時間 4,620 ms
コンパイル使用メモリ 85,392 KB
実行使用メモリ 56,044 KB
最終ジャッジ日時 2023-09-20 20:05:33
合計ジャッジ時間 7,922 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,760 KB
testcase_01 AC 118 ms
55,552 KB
testcase_02 AC 118 ms
55,656 KB
testcase_03 AC 120 ms
54,412 KB
testcase_04 AC 118 ms
55,532 KB
testcase_05 AC 117 ms
55,800 KB
testcase_06 AC 119 ms
55,864 KB
testcase_07 AC 119 ms
55,932 KB
testcase_08 AC 120 ms
55,708 KB
testcase_09 AC 119 ms
56,044 KB
testcase_10 AC 120 ms
55,656 KB
testcase_11 AC 119 ms
55,548 KB
testcase_12 AC 120 ms
55,684 KB
testcase_13 AC 121 ms
55,952 KB
testcase_14 AC 120 ms
55,680 KB
testcase_15 AC 119 ms
55,792 KB
testcase_16 AC 118 ms
55,988 KB
testcase_17 AC 119 ms
55,848 KB
testcase_18 AC 118 ms
55,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final String S = sc.next();
		
		int max = Integer.MIN_VALUE;
		for(int slide = 0; slide < S.length(); slide++){
			final String rotated = S.substring(slide) + S.substring(0, slide);
			
			if(rotated.charAt(0) == '+' || rotated.charAt(0) == '-'){
				continue;
			}else if(rotated.charAt(rotated.length() - 1) == '+' || rotated.charAt(rotated.length() - 1) == '-'){
				continue;
			}
			
			char[] in = rotated.toCharArray();
			int current = 0, cur_pos = 0;
			while(cur_pos < in.length && '0' <= in[cur_pos] && in[cur_pos] <= '9'){
				current *= 10;
				current += Character.getNumericValue(in[cur_pos++]);
			}
			
			while(cur_pos < in.length){
				final int sign = in[cur_pos] == '+' ? 1 : -1;
				cur_pos++;
				
				int snd = 0;
				while(cur_pos < in.length && '0' <= in[cur_pos] && in[cur_pos] <= '9'){
					snd *= 10;
					snd += Character.getNumericValue(in[cur_pos++]);
				}
				
				current += sign * snd;
			}
			
			max = Math.max(max, current);
		}
		
		System.out.println(max);
	}
	
}
0