結果

問題 No.222 引き算と足し算
ユーザー tsunabittsunabit
提出日時 2020-03-16 19:25:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 1,000 ms
コード長 1,010 bytes
コンパイル時間 3,705 ms
コンパイル使用メモリ 75,100 KB
実行使用メモリ 56,444 KB
最終ジャッジ日時 2023-08-18 19:25:29
合計ジャッジ時間 9,954 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,380 KB
testcase_01 AC 121 ms
55,784 KB
testcase_02 AC 119 ms
55,480 KB
testcase_03 AC 120 ms
55,388 KB
testcase_04 AC 120 ms
55,764 KB
testcase_05 AC 121 ms
55,804 KB
testcase_06 AC 121 ms
55,644 KB
testcase_07 AC 120 ms
55,540 KB
testcase_08 AC 122 ms
55,688 KB
testcase_09 AC 124 ms
55,408 KB
testcase_10 AC 121 ms
55,604 KB
testcase_11 AC 122 ms
55,664 KB
testcase_12 AC 123 ms
55,652 KB
testcase_13 AC 123 ms
55,720 KB
testcase_14 AC 127 ms
55,688 KB
testcase_15 AC 123 ms
55,808 KB
testcase_16 AC 122 ms
55,812 KB
testcase_17 AC 122 ms
55,612 KB
testcase_18 AC 120 ms
55,716 KB
testcase_19 AC 120 ms
55,832 KB
testcase_20 AC 120 ms
55,580 KB
testcase_21 AC 119 ms
55,808 KB
testcase_22 AC 120 ms
55,712 KB
testcase_23 AC 123 ms
55,408 KB
testcase_24 AC 123 ms
55,692 KB
testcase_25 AC 120 ms
56,040 KB
testcase_26 AC 119 ms
56,444 KB
testcase_27 AC 119 ms
55,696 KB
testcase_28 AC 120 ms
55,892 KB
testcase_29 AC 122 ms
55,708 KB
testcase_30 AC 124 ms
55,672 KB
testcase_31 AC 119 ms
55,872 KB
testcase_32 AC 120 ms
55,688 KB
testcase_33 AC 120 ms
55,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No222 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int k = 0;
		for(int i = 1; i < s.length(); i++) {
			if(s.charAt(i) == '+' || s.charAt(i) == '-') {
				if(s.charAt(i-1) != '+' && s.charAt(i-1) != '-') {
					k = i;
				}
			}
		}
		int sa = 0;
		if(s.charAt(0) == '-') {
			sa = -1 * Integer.parseInt(s.substring(1, k));
		}else if(s.charAt(0) == '+') {
			sa = Integer.parseInt(s.substring(1, k));
		}else {
			sa = Integer.parseInt(s.substring(0, k));
		}
		
		int u = 0;
		if(s.charAt(k+1) == '-') {
			u = -1 * Integer.parseInt(s.substring(k+2));
		}else if(s.charAt(k+1) == '+') {
			u = Integer.parseInt(s.substring(k+2));
		}else {
			u = Integer.parseInt(s.substring(k+1));
		}
		
		if(s.charAt(k) == '+') {
			if(u < 0) {
				u = -1 * u;
				System.out.println(sa + u);
			}else {
				System.out.println(sa - u);
			}
		}
		else System.out.println(sa + u);
	}
}
0