結果

問題 No.222 引き算と足し算
ユーザー papinianuspapinianus
提出日時 2016-09-21 12:31:56
言語 PHP
(8.3.4)
結果
AC  
実行時間 45 ms / 1,000 ms
コード長 582 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 30,880 KB
実行使用メモリ 31,344 KB
最終ジャッジ日時 2024-04-28 16:41:55
合計ジャッジ時間 2,664 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
31,096 KB
testcase_01 AC 45 ms
30,960 KB
testcase_02 AC 42 ms
31,344 KB
testcase_03 AC 41 ms
31,188 KB
testcase_04 AC 41 ms
31,064 KB
testcase_05 AC 41 ms
31,036 KB
testcase_06 AC 40 ms
30,944 KB
testcase_07 AC 40 ms
31,004 KB
testcase_08 AC 40 ms
31,028 KB
testcase_09 AC 40 ms
30,928 KB
testcase_10 AC 41 ms
30,900 KB
testcase_11 AC 40 ms
31,292 KB
testcase_12 AC 40 ms
31,008 KB
testcase_13 AC 40 ms
31,192 KB
testcase_14 AC 41 ms
31,224 KB
testcase_15 AC 41 ms
31,012 KB
testcase_16 AC 40 ms
31,248 KB
testcase_17 AC 41 ms
31,244 KB
testcase_18 AC 41 ms
31,200 KB
testcase_19 AC 41 ms
31,012 KB
testcase_20 AC 41 ms
31,252 KB
testcase_21 AC 40 ms
31,096 KB
testcase_22 AC 41 ms
31,028 KB
testcase_23 AC 40 ms
31,280 KB
testcase_24 AC 40 ms
31,284 KB
testcase_25 AC 41 ms
31,160 KB
testcase_26 AC 41 ms
31,068 KB
testcase_27 AC 40 ms
31,116 KB
testcase_28 AC 39 ms
31,168 KB
testcase_29 AC 41 ms
31,172 KB
testcase_30 AC 40 ms
31,152 KB
testcase_31 AC 40 ms
30,956 KB
testcase_32 AC 41 ms
31,004 KB
testcase_33 AC 41 ms
31,064 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$str = trim(fgets(STDIN));
$pattern = "/([+-]?[0-9]+)([+-])([+-]?[0-9]+)/";
preg_match_all($pattern, $str, $matches);
$first = getval($matches[1][0]);
$second = getval($matches[3][0]);
if($matches[2][0] == "+")
{
    $ans = $first - $second;
}
else {
    $ans = $first + $second;
}

echo $ans.PHP_EOL;

function getval($str)
{
    $minus = false;
    $index = 0;
    if($str[0] == "+")
    {
        $index = 1;
    }
    if($str[0] == "-")
    {
        $index = 1;
        $minus = true;
    }
    $temp = strval(substr($str, $index));
    return ($minus)?(-$temp):$temp;
}
0