結果

問題 No.222 引き算と足し算
ユーザー はむ吉🐹
提出日時 2015-12-28 17:15:35
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 31 ms / 1,000 ms
コード長 422 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-11-15 22:08:41
合計ジャッジ時間 2,022 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.py:8: SyntaxWarning: invalid escape sequence '\+'
  pattern = re.compile("(?P<x>[\+\-]?\d+)(?P<op>[\+\-])(?P<y>[\+\-]?\d+)")

ソースコード

diff #

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import re


def calc(input_str):
    pattern = re.compile("(?P<x>[\+\-]?\d+)(?P<op>[\+\-])(?P<y>[\+\-]?\d+)")
    match_obj = pattern.match(input_str)
    x = int(match_obj.group("x"))
    y = int(match_obj.group("y"))
    op = match_obj.group("op")
    if op == "+":
        return x - y
    else:
        return x + y


if __name__ == "__main__":
    print(calc(input()))
0