結果

問題 No.222 引き算と足し算
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-15 18:10:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 1,000 ms
コード長 884 bytes
コンパイル時間 2,626 ms
コンパイル使用メモリ 71,420 KB
実行使用メモリ 57,876 KB
最終ジャッジ日時 2023-08-27 02:34:36
合計ジャッジ時間 8,550 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,628 KB
testcase_01 AC 121 ms
55,612 KB
testcase_02 AC 121 ms
55,872 KB
testcase_03 AC 119 ms
55,756 KB
testcase_04 AC 119 ms
55,660 KB
testcase_05 AC 121 ms
55,928 KB
testcase_06 AC 119 ms
55,636 KB
testcase_07 AC 122 ms
55,252 KB
testcase_08 AC 120 ms
55,536 KB
testcase_09 AC 120 ms
55,404 KB
testcase_10 AC 123 ms
57,876 KB
testcase_11 AC 121 ms
57,552 KB
testcase_12 AC 121 ms
55,636 KB
testcase_13 AC 121 ms
55,904 KB
testcase_14 AC 121 ms
55,600 KB
testcase_15 AC 120 ms
55,912 KB
testcase_16 AC 121 ms
55,688 KB
testcase_17 AC 118 ms
55,568 KB
testcase_18 AC 118 ms
55,744 KB
testcase_19 AC 115 ms
55,720 KB
testcase_20 AC 115 ms
55,692 KB
testcase_21 AC 113 ms
55,844 KB
testcase_22 AC 121 ms
55,300 KB
testcase_23 AC 112 ms
55,552 KB
testcase_24 AC 115 ms
55,460 KB
testcase_25 AC 110 ms
55,488 KB
testcase_26 AC 111 ms
55,320 KB
testcase_27 AC 110 ms
55,628 KB
testcase_28 AC 114 ms
53,504 KB
testcase_29 AC 112 ms
55,964 KB
testcase_30 AC 114 ms
55,568 KB
testcase_31 AC 113 ms
55,860 KB
testcase_32 AC 112 ms
55,836 KB
testcase_33 AC 113 ms
55,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		String s = sc.next();
		
		//まずは、+あるいは-の位置と、それが+か-のどちらなのかを探る
		//左辺が負の場合、それに反応してしまうので、最初の一文字目はスルーする
		char operater = ' ';
		int pos = 0;
		for (int i=0; i<s.length(); i++) {
			if (s.charAt(i)=='+' || s.charAt(i)=='-') {
				if (i==0) {continue;}
				operater = s.charAt(i);
				pos = i;
				break;
			}
		}
		
		//次、演算子の左側と右側とに分ける
		int left = Integer.parseInt(s.substring(0,pos));
		int right = Integer.parseInt(s.substring(pos+1,s.length()));
		
		//出力。演算子の意味を逆にしなければならないことに注意。
		System.out.println(operater=='-'?left+right:left-right);
	}
}
0