結果

問題 No.222 引き算と足し算
ユーザー marumaru
提出日時 2016-05-03 18:47:52
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 904 bytes
コンパイル時間 2,914 ms
コンパイル使用メモリ 74,960 KB
実行使用メモリ 41,136 KB
最終ジャッジ日時 2024-04-27 17:52:13
合計ジャッジ時間 7,280 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
39,764 KB
testcase_01 AC 97 ms
40,024 KB
testcase_02 AC 103 ms
40,972 KB
testcase_03 AC 105 ms
41,008 KB
testcase_04 AC 94 ms
39,784 KB
testcase_05 WA -
testcase_06 AC 106 ms
40,944 KB
testcase_07 AC 108 ms
41,136 KB
testcase_08 WA -
testcase_09 AC 101 ms
41,020 KB
testcase_10 AC 86 ms
39,428 KB
testcase_11 WA -
testcase_12 AC 103 ms
40,672 KB
testcase_13 AC 99 ms
40,916 KB
testcase_14 WA -
testcase_15 AC 106 ms
40,708 KB
testcase_16 AC 91 ms
39,652 KB
testcase_17 WA -
testcase_18 AC 99 ms
40,752 KB
testcase_19 AC 109 ms
40,704 KB
testcase_20 WA -
testcase_21 AC 105 ms
40,536 KB
testcase_22 WA -
testcase_23 AC 101 ms
41,028 KB
testcase_24 AC 94 ms
39,804 KB
testcase_25 WA -
testcase_26 AC 94 ms
39,692 KB
testcase_27 AC 108 ms
40,988 KB
testcase_28 WA -
testcase_29 AC 100 ms
40,712 KB
testcase_30 AC 96 ms
39,848 KB
testcase_31 AC 99 ms
40,948 KB
testcase_32 AC 102 ms
40,048 KB
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = "+";
		
		Pattern p = Pattern.compile("^[-]?[0-9]{1,6}");
		Matcher m = p.matcher(str);
		
		if (m.find()) {
			String matchstr =m.group();
			
			int n1 = Integer.parseInt(matchstr);
			int 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) == "-") {
					result = n1 + Math.abs(n2);
				} else {
					result = n1 - n2;
				}
			} else {
				result = n1 + n2;
			}
			System.out.println(result);
			
		} else {
			System.out.println("no matches!");
		}
		
	}
}
	
0