結果
問題 | No.193 筒の数式 |
ユーザー | kou6839 |
提出日時 | 2015-04-29 01:16:03 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 115 ms / 1,000 ms |
コード長 | 1,122 bytes |
コンパイル時間 | 1,856 ms |
コンパイル使用メモリ | 79,020 KB |
実行使用メモリ | 41,472 KB |
最終ジャッジ日時 | 2024-07-05 16:23:13 |
合計ジャッジ時間 | 4,661 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
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); } }