結果

問題 No.49 算数の宿題
コンテスト
ユーザー kuramu
提出日時 2016-02-11 10:43:36
言語 Java
(openjdk 27 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,462 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,358 ms
コンパイル使用メモリ 84,928 KB
実行使用メモリ 43,632 KB
最終ジャッジ日時 2026-10-11 22:52:33
合計ジャッジ時間 2,694 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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();
	      }
	}
}
0