結果

問題 No.222 引き算と足し算
ユーザー Grenache
提出日時 2015-06-08 12:12:34
言語 Java
(openjdk 23)
結果
AC  
実行時間 130 ms / 1,000 ms
コード長 790 bytes
コンパイル時間 3,480 ms
コンパイル使用メモリ 75,560 KB
実行使用メモリ 41,632 KB
最終ジャッジ日時 2024-11-15 21:54:05
合計ジャッジ時間 8,806 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

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


public class Main_yukicoder222 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String xopy = sc.next();

        String regex = "([+-]?\\d+)([+-])([+-]?\\d+)";
        Pattern p = Pattern.compile(regex);
        
        Matcher m = p.matcher(xopy);
        if (m.find()) {
        	int x = Integer.parseInt(m.group(1));
        	String op = m.group(2);
        	int y = Integer.parseInt(m.group(3));
        	
        	if (op.equals("+")) {
        		System.out.println(x - y);
        	} else {
        		System.out.println(x + y);
        	}
        } else {
        	System.out.println("NG");
        }
        
        sc.close();
    }
}
0