結果

問題 No.222 引き算と足し算
ユーザー marumaru
提出日時 2016-05-03 19:14:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 1,000 ms
コード長 1,246 bytes
コンパイル時間 3,395 ms
コンパイル使用メモリ 77,872 KB
実行使用メモリ 54,208 KB
最終ジャッジ日時 2024-04-27 17:52:23
合計ジャッジ時間 8,631 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
54,208 KB
testcase_01 AC 110 ms
52,580 KB
testcase_02 AC 113 ms
52,948 KB
testcase_03 AC 125 ms
54,060 KB
testcase_04 AC 127 ms
54,044 KB
testcase_05 AC 123 ms
54,080 KB
testcase_06 AC 112 ms
52,900 KB
testcase_07 AC 123 ms
54,140 KB
testcase_08 AC 121 ms
53,836 KB
testcase_09 AC 122 ms
54,052 KB
testcase_10 AC 123 ms
53,868 KB
testcase_11 AC 123 ms
54,208 KB
testcase_12 AC 124 ms
54,028 KB
testcase_13 AC 109 ms
52,704 KB
testcase_14 AC 121 ms
53,980 KB
testcase_15 AC 123 ms
54,020 KB
testcase_16 AC 123 ms
53,792 KB
testcase_17 AC 110 ms
52,952 KB
testcase_18 AC 127 ms
53,864 KB
testcase_19 AC 109 ms
52,948 KB
testcase_20 AC 125 ms
54,100 KB
testcase_21 AC 126 ms
53,904 KB
testcase_22 AC 127 ms
54,016 KB
testcase_23 AC 126 ms
53,848 KB
testcase_24 AC 124 ms
53,756 KB
testcase_25 AC 126 ms
53,964 KB
testcase_26 AC 121 ms
53,848 KB
testcase_27 AC 125 ms
54,120 KB
testcase_28 AC 124 ms
54,184 KB
testcase_29 AC 126 ms
53,984 KB
testcase_30 AC 121 ms
53,940 KB
testcase_31 AC 123 ms
54,140 KB
testcase_32 AC 110 ms
52,972 KB
testcase_33 AC 123 ms
53,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class yukicoder_222 {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		String str = stdIn.next();
		final String PLUS = "+";
		final String MINUS = "-";
		
		Pattern p = Pattern.compile("^[-+]?[0-9]{1,6}");
		Matcher m = p.matcher(str);
		
		if (m.find()) {
			String matchstr = m.group();
			String matchstr1 = matchstr;
			
			if(matchstr.substring(0, 1).equals(PLUS)) {
				matchstr1 = matchstr.substring(1);
			}
			
			int n1 = Integer.parseInt(matchstr1);
			int n2;
			
			if (str.substring(matchstr.length() + 1,matchstr.length() + 2).equals(PLUS)) {
				n2 = Integer.parseInt(str.substring(matchstr.length() + 2));
			} else {
				n2 = Integer.parseInt(str.substring(matchstr.length() + 1));
			}
				
			int result = 0;
			
			if (str.substring(matchstr.length(),matchstr.length() + 1).equals(PLUS)) {
				if (str.substring(matchstr.length() + 1,matchstr.length() + 2).equals(MINUS)) {
					result = n1 + Math.abs(n2);
				} else {
					result = n1 - n2;
				}
			} else {
				result = n1 + n2;
			}
			System.out.println(result);
			
		} else {
			System.out.println("no matches!");
		}
		
	}
}
	
0