結果
| 問題 |
No.49 算数の宿題
|
| コンテスト | |
| ユーザー |
kuramu
|
| 提出日時 | 2016-02-11 10:43:36 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 57 ms / 5,000 ms |
| コード長 | 1,462 bytes |
| コンパイル時間 | 2,886 ms |
| コンパイル使用メモリ | 76,200 KB |
| 実行使用メモリ | 37,080 KB |
| 最終ジャッジ日時 | 2024-12-23 01:48:42 |
| 合計ジャッジ時間 | 3,407 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
try {
String line = stdReader.readLine();
int ans = 0;
int index = 0;
String op = "";
for(int i=0;i<line.length();i++){
if(line.charAt(i) == '+'){
if(op.equals("+")){
ans += Integer.parseInt(line.substring(index, i));
}else if(op.equals("*")){
ans *= Integer.parseInt(line.substring(index, i));
}else{
ans = Integer.parseInt(line.substring(index, i));
}
op = "*";
index = i+1;
}else if(line.charAt(i) == '*'){
if(op.equals("+")){
ans += Integer.parseInt(line.substring(index, i));
}else if(op.equals("*")){
ans *= Integer.parseInt(line.substring(index, i));
}else{
ans = Integer.parseInt(line.substring(index, i));
}
op = "+";
index = i+1;
}
}
if(op.equals("+")){
ans += Integer.parseInt(line.substring(index, line.length()));
}else if(op.equals("*")){
ans *= Integer.parseInt(line.substring(index, line.length()));
}
System.out.println(ans);
} catch (IOException e) {
e.printStackTrace();
}
}
}
kuramu