結果

問題 No.193 筒の数式
ユーザー kou6839kou6839
提出日時 2015-04-29 01:16:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 1,000 ms
コード長 1,122 bytes
コンパイル時間 2,593 ms
コンパイル使用メモリ 76,168 KB
実行使用メモリ 55,896 KB
最終ジャッジ日時 2023-09-19 03:46:36
合計ジャッジ時間 6,323 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,896 KB
testcase_01 AC 124 ms
55,456 KB
testcase_02 AC 123 ms
55,644 KB
testcase_03 AC 122 ms
55,204 KB
testcase_04 AC 122 ms
55,364 KB
testcase_05 AC 123 ms
55,420 KB
testcase_06 AC 123 ms
55,216 KB
testcase_07 AC 124 ms
55,592 KB
testcase_08 AC 122 ms
55,588 KB
testcase_09 AC 123 ms
55,772 KB
testcase_10 AC 122 ms
55,504 KB
testcase_11 AC 123 ms
55,592 KB
testcase_12 AC 123 ms
55,600 KB
testcase_13 AC 124 ms
55,632 KB
testcase_14 AC 123 ms
55,324 KB
testcase_15 AC 125 ms
55,348 KB
testcase_16 AC 122 ms
55,348 KB
testcase_17 AC 123 ms
55,448 KB
testcase_18 AC 122 ms
55,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static long cul(String a){
		int now=0;
		long ret = 0;
		while(now<a.length() && Character.isDigit(a.charAt(now)) ){
			now++;
		}
		ret=Long.parseLong(a.substring(0, now));
		while(now<a.length()){
			if(a.charAt(now)=='-'){
				now++;
				int s=now;
				while(now<a.length() && Character.isDigit(a.charAt(now)) ){
					now++;
				}
				ret-=Long.parseLong(a.substring(s,now));
				
			}else{
				now++;
				int s=now;
				while(now<a.length() && Character.isDigit(a.charAt(now)) ){
					now++;
				}
				ret+=Long.parseLong(a.substring(s,now));
			}
		}
		return ret;
	}
	public static void main(String[] args){
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		long ans=cul(a);
		int le = a.length();
		a+=a;
		for(int i=1;i<le;i++){
			if(a.substring(i, i+le).indexOf("-")!=0 &&a.substring(i, i+le).indexOf("+")!=0 &&a.substring(i, i+le).lastIndexOf("-")!=(le-1) &&a.substring(i, i+le).lastIndexOf("+")!=(le-1)  ){
				ans=Math.max(ans, cul(a.substring(i,i+le)));
			}
		}
		System.out.println(ans);
	}
}
0