結果
問題 |
No.193 筒の数式
|
ユーザー |
![]() |
提出日時 | 2015-04-26 22:47:22 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,119 bytes |
コンパイル時間 | 2,150 ms |
コンパイル使用メモリ | 78,008 KB |
実行使用メモリ | 41,472 KB |
最終ジャッジ日時 | 2024-07-05 03:12:01 |
合計ジャッジ時間 | 5,078 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 WA * 5 |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); char[] line = sc.next().toCharArray(); sc.close(); long max = 0; for (int q = 0; q < line.length; q++) { if (Character.isDigit(line[0]) && Character.isDigit(line[line.length - 1])) { long sum = 0; boolean plus = true; StringBuilder sb = new StringBuilder(); for (int i = 0; i < line.length; i++) { if (Character.isDigit(line[i])) { sb.append(line[i]); } else { if (plus) { sum += Long.parseLong(sb.toString()); } else { sum -= Long.parseLong(sb.toString()); } sb.setLength(0); if (line[i] == '+') { plus = true; } else { plus = false; } } } if (plus) { sum += Long.parseLong(sb.toString()); } else { sum -= Long.parseLong(sb.toString()); } max = Math.max(max, sum); } char tmp = line[0]; for (int i = 1; i < line.length; i++) { line[i - 1] = line[i]; } line[line.length - 1] = tmp; } System.out.println(max); } }