結果
問題 | No.193 筒の数式 |
ユーザー | kohaku_kohaku |
提出日時 | 2016-12-09 04:19:38 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 107 ms / 1,000 ms |
コード長 | 1,325 bytes |
コンパイル時間 | 1,803 ms |
コンパイル使用メモリ | 76,412 KB |
実行使用メモリ | 57,808 KB |
最終ジャッジ日時 | 2023-08-19 03:03:30 |
合計ジャッジ時間 | 5,332 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 102 ms
55,816 KB |
testcase_01 | AC | 101 ms
56,224 KB |
testcase_02 | AC | 101 ms
55,868 KB |
testcase_03 | AC | 102 ms
56,256 KB |
testcase_04 | AC | 100 ms
55,948 KB |
testcase_05 | AC | 100 ms
56,188 KB |
testcase_06 | AC | 101 ms
55,768 KB |
testcase_07 | AC | 101 ms
56,160 KB |
testcase_08 | AC | 102 ms
57,808 KB |
testcase_09 | AC | 101 ms
55,476 KB |
testcase_10 | AC | 103 ms
54,728 KB |
testcase_11 | AC | 104 ms
55,636 KB |
testcase_12 | AC | 107 ms
55,848 KB |
testcase_13 | AC | 101 ms
55,848 KB |
testcase_14 | AC | 100 ms
56,128 KB |
testcase_15 | AC | 103 ms
55,764 KB |
testcase_16 | AC | 104 ms
56,176 KB |
testcase_17 | AC | 102 ms
53,776 KB |
testcase_18 | AC | 102 ms
55,936 KB |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String S = sc.next(); String [] arr = S.split(""); int L = S.length(); int max=Integer.MIN_VALUE; for(int j=0; j<L; j++){ String t = ""; for(int i=0; i<L; i++){ t+=arr[(i+j)%L]; } int a=t.charAt(0); int z=t.charAt(L-1); if(a>='0'&&a<='9'&&z>='0'&&z<='9'){ int num = cal(t); max=Math.max(max,num); } } System.out.println(max); } static int cal(String S){ String [] integer = S.split("[+-]"); int N = integer.length; int [] z = new int [N]; for(int i=0; i<N; i++){ z[i]=Integer.parseInt(integer[i]); } int r = z[0]; int [] sign = new int [N-1]; int j=0; for(int i=0; i<S.length(); i++){ int tmp=S.charAt(i); if(tmp=='+'||tmp=='-'){ sign[j]=tmp; j++; } } for(int i=0; i<N-1; i++){ if(sign[i]=='+'){ r+=z[i+1]; }else{ r-=z[i+1]; } } return r; } }