結果

問題 No.49 算数の宿題
ユーザー 明智重蔵明智重蔵
提出日時 2015-10-31 20:48:36
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 1,467 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 105,700 KB
実行使用メモリ 23,940 KB
最終ジャッジ日時 2023-08-24 17:27:12
合計ジャッジ時間 3,456 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
23,864 KB
testcase_01 AC 58 ms
19,892 KB
testcase_02 AC 60 ms
23,908 KB
testcase_03 AC 60 ms
21,828 KB
testcase_04 AC 59 ms
23,940 KB
testcase_05 AC 59 ms
21,740 KB
testcase_06 AC 60 ms
21,896 KB
testcase_07 AC 58 ms
21,948 KB
testcase_08 AC 59 ms
23,864 KB
testcase_09 AC 59 ms
21,808 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;

class Program
{
    static string InputPattern = "InputX";

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

        if (InputPattern == "Input1") {
            WillReturn.Add("2*3");
            //5
            //太郎君の国では、記号'*'は足し算を表します。
            //2と3を足して5が解になります
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("6*7+2");
            //26
            //我々の世界の表記に直すと 6+7×2ですが、
            //優先度が無いため6と7を足してから2を掛けます
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("2497*3+4");
            //10000
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[0];
        int[] ValArr = S.Split('+', '*').Select(X => int.Parse(X)).ToArray();

        int AppearOpeCnt = 0;
        int Answer = ValArr[0];
        foreach (char EachChar in S) {
            if (EachChar == '+') Answer *= ValArr[++AppearOpeCnt];
            if (EachChar == '*') Answer += ValArr[++AppearOpeCnt];
        }
        Console.WriteLine(Answer);
    }
}
0