結果

問題 No.222 引き算と足し算
ユーザー aketijyuuzou
提出日時 2024-10-10 23:39:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 90 ms / 1,000 ms
コード長 1,303 bytes
コンパイル時間 1,013 ms
コンパイル使用メモリ 113,784 KB
実行使用メモリ 30,676 KB
最終ジャッジ日時 2024-10-10 23:39:56
合計ジャッジ時間 4,758 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("5+3");
            //2
            //入力は5+3ですが、5 - 3の演算の結果である2を出力します。
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("10-20");
            //30
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("-2+-3");
            //1
            //入力のx,yが符号を含む場合があります。
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        Match InsMatch = Regex.Match(InputList[0], @"([-+]?[0-9]+)([-+])([-+]?[0-9]+)$");
        int X = int.Parse(InsMatch.Groups[1].Value);
        string Ope = InsMatch.Groups[2].Value;
        int Y = int.Parse(InsMatch.Groups[3].Value);

        if (Ope == "+") Console.WriteLine(X - Y);
        else Console.WriteLine(X + Y);
    }
}

0