結果

問題 No.222 引き算と足し算
ユーザー minus9d
提出日時 2015-06-05 23:48:09
言語 Java
(openjdk 23)
結果
AC  
実行時間 129 ms / 1,000 ms
コード長 721 bytes
コンパイル時間 2,582 ms
コンパイル使用メモリ 75,564 KB
実行使用メモリ 41,624 KB
最終ジャッジ日時 2024-11-15 21:29:08
合計ジャッジ時間 7,383 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

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


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

        Scanner s = new Scanner(str);
        s.findInLine("([+-]?\\d+)([+-])([+-]?\\d+)");
        MatchResult result = s.match();

        int n1 = Integer.parseInt(result.group(1));
        int n2 = Integer.parseInt(result.group(3));
        String sign = result.group(2);

        if (sign.equals("+")) {
            System.out.println(n1 - n2);
        }
        else {
            System.out.println(n1 + n2);
        }
    }
}
0