結果
問題 |
No.222 引き算と足し算
|
ユーザー |
|
提出日時 | 2017-04-02 14:54:20 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 802 bytes |
コンパイル時間 | 3,490 ms |
コンパイル使用メモリ | 75,556 KB |
実行使用メモリ | 54,152 KB |
最終ジャッジ日時 | 2024-07-08 00:08:23 |
合計ジャッジ時間 | 7,880 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 RE * 4 |
ソースコード
import java.util.Scanner; public class Tashihiki { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner s = new Scanner(System.in); StringBuilder str = new StringBuilder(s.nextLine()); s.close(); int sum = 0; int lp = str.lastIndexOf("+"),lm = str.lastIndexOf("-"); int b = Integer.parseInt(str.substring(Math.max(lp, lm), str.length())); str.delete(Math.max(lm, lp), str.length()); lp = str.lastIndexOf("+"); lm = str.lastIndexOf("-"); if(lp == -1&&lm == -1){ sum = Integer.parseInt(str.toString()) - b; }else{ int a = Integer.parseInt(str.substring(0, Math.max(lm, lp))); str.delete(0, Math.max(lp, lm)); if(str.charAt(0) == '+'){ sum = a-b; }else{ sum = a+b; } } System.out.println(sum); } }