結果
問題 | No.49 算数の宿題 |
ユーザー |
![]() |
提出日時 | 2019-09-14 14:10:22 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 140 ms / 5,000 ms |
コード長 | 1,170 bytes |
コンパイル時間 | 2,802 ms |
コンパイル使用メモリ | 80,380 KB |
実行使用メモリ | 41,496 KB |
最終ジャッジ日時 | 2024-12-23 02:04:39 |
合計ジャッジ時間 | 4,893 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
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(i == s.length() - 1) { if(c.equals("*")) { ans += d; } else { ans *= d; } } } } System.out.println(ans); } }