結果
問題 | No.193 筒の数式 |
ユーザー |
|
提出日時 | 2016-02-14 19:32:47 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 130 ms / 1,000 ms |
コード長 | 992 bytes |
コンパイル時間 | 3,447 ms |
コンパイル使用メモリ | 79,524 KB |
実行使用メモリ | 55,968 KB |
最終ジャッジ日時 | 2024-09-22 06:36:26 |
合計ジャッジ時間 | 6,758 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
import java.util.Scanner; public class Main_yukicoder193 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); int n = s.length(); s = s + s; int max = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { max = Math.max(max, calc(s.substring(i, i + n))); } System.out.println(max); sc.close(); } private static int calc(String str) { int n = str.length(); if (str.charAt(0) == '+' || str.charAt(0) == '-') { return Integer.MIN_VALUE; } if (str.charAt(n - 1) == '+' || str.charAt(n - 1) == '-') { return Integer.MIN_VALUE; } int i; int j = 0; int ret = 0; for (i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == '+' || c == '-') { int tmp = Integer.parseInt(str.substring(j, i)); ret += tmp; j = i; } } int tmp = Integer.parseInt(str.substring(j, i)); ret += tmp; return ret; } }