結果
問題 | No.49 算数の宿題 |
ユーザー |
![]() |
提出日時 | 2019-09-14 13:58:16 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,201 bytes |
コンパイル時間 | 2,565 ms |
コンパイル使用メモリ | 79,744 KB |
実行使用メモリ | 41,656 KB |
最終ジャッジ日時 | 2024-12-23 02:04:46 |
合計ジャッジ時間 | 4,669 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 WA * 9 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); int ans = 0; String st = ""; int p = 0; String c = ""; for(int i = 0; i < s.length(); i++) { String str = String.valueOf(s.charAt(i)); if(str.equals("*")) { int d = Integer.parseInt(st); st = ""; if(p == 0) { ans += d; } else { if(c.equals("*")) { ans += d; } else { ans *= d; } } p++; c = "*"; } else if(str.equals("+")) { int d = Integer.parseInt(st); st = ""; if(p == 0) { ans += d; } else { if(c.equals("*")) { ans += d; } else { ans *= d; } } p++; c = "+"; } else { st += str; int d = Integer.parseInt(st); if(p == 0) { if(i == s.length() - 1) { if(c.equals("*")) { ans += d; } else { ans *= d; } } } } } System.out.println(ans); } }