結果
| 問題 |
No.49 算数の宿題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-04-02 11:19:54 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 143 ms / 5,000 ms |
| コード長 | 1,060 bytes |
| コンパイル時間 | 3,862 ms |
| コンパイル使用メモリ | 77,648 KB |
| 実行使用メモリ | 41,640 KB |
| 最終ジャッジ日時 | 2024-12-23 01:56:58 |
| 合計ジャッジ時間 | 5,942 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
import java.util.Scanner;
public class Sansunoshukudai {
static StringBuilder str = new StringBuilder();
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Scanner s = new Scanner(System.in);
str.append(s.nextLine());
s.close();
int sum = 0;
while(str.length() != 0){
char c = str.charAt(0);
if(c == '*'){
str.deleteCharAt(0);
sum += getnum();
}else if(c == '+'){
str.deleteCharAt(0);
sum *= getnum();
}else{
sum += getnum();
}
}
System.out.println(sum);
}
static int getnum(){
int p = str.indexOf("*");
int m = str.indexOf("+");
int num = 0;
if(p != -1 && m != -1){
num = Integer.parseInt(str.substring(0, Math.min(p, m)));
str.delete(0, Math.min(p, m));
}else if(p != -1){
num = Integer.parseInt(str.substring(0, p));
str.delete(0, p);
}else if(m != -1){
num = Integer.parseInt(str.substring(0, m));
str.delete(0, m);
}else{
num = Integer.parseInt(str.toString());
str.delete(0, str.length());
}
return num;
}
}