結果

問題 No.49 算数の宿題
ユーザー eitahoeitaho
提出日時 2015-06-13 13:07:15
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 2,520 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 112,160 KB
実行使用メモリ 23,956 KB
最終ジャッジ日時 2023-08-24 17:26:06
合計ジャッジ時間 3,531 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
21,964 KB
testcase_01 AC 62 ms
21,928 KB
testcase_02 AC 63 ms
23,956 KB
testcase_03 AC 63 ms
21,908 KB
testcase_04 AC 63 ms
23,900 KB
testcase_05 AC 63 ms
19,792 KB
testcase_06 AC 62 ms
19,828 KB
testcase_07 AC 62 ms
21,848 KB
testcase_08 AC 62 ms
21,840 KB
testcase_09 AC 62 ms
19,828 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.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

class Program
{
    public void Solve()
    {
        var S = Reader.String().Replace("+", "!").Replace("*", "+").Replace("!", "*");
        S += "!";
        var opIndex = Enu.Range(0, S.Length).Where(i => !char.IsDigit(S[i])).ToArray();
        int ans = int.Parse(S.Substring(0, opIndex[0]));

        for (int i = 0; i + 1 < opIndex.Length; i++)
        {
            int x = int.Parse(S.Substring(opIndex[i] + 1, opIndex[i + 1] - opIndex[i] - 1));
            if (S[opIndex[i]] == '+') ans += x;
            if (S[opIndex[i]] == '*') ans *= x;
        }

        Console.WriteLine(ans);
    }

}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    private static TextReader reader = Console.In;
    private static readonly char[] separator = { ' ' };
    private static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    private static string[] A = new string[0];
    private static int i;
    private static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); }
    public static int[][] IntTable(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); }
    public static string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Line()).ToArray(); }
    public static string Line() { return reader.ReadLine().Trim(); }
    private static string[] Split(string s) { return s.Split(separator, op); }
    private static string Next() { CheckNext(); return A[i++]; }
    private static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}
0