結果
問題 | No.49 算数の宿題 |
ユーザー |
![]() |
提出日時 | 2014-12-22 23:54:29 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 130 ms / 5,000 ms |
コード長 | 851 bytes |
コンパイル時間 | 2,367 ms |
コンパイル使用メモリ | 78,220 KB |
実行使用メモリ | 47,552 KB |
最終ジャッジ日時 | 2024-12-23 01:43:17 |
合計ジャッジ時間 | 4,309 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
import java.math.*;import java.util.*;class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);String s = sc.next();ArrayList<Integer> num = new ArrayList<>();for(int i=0;i<s.length();){if('0'<=s.charAt(i) && s.charAt(i)<='9'){int j=i+1;while( j<s.length() && ('0'<=s.charAt(j) && s.charAt(j)<='9')){j++;}num.add(Integer.parseInt(s.substring(i, j)));i=j+1;}}int ans = num.get(0);int count=1;for(int i=0;i<s.length();i++){if(s.charAt(i)=='*'){ans += num.get(count);count++;}else if(s.charAt(i)=='+'){ans *= num.get(count);count++;}}System.out.println(ans);}}