結果

問題 No.49 算数の宿題
ユーザー nanophoto12
提出日時 2014-11-05 01:38:14
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 1,173 bytes
コンパイル時間 3,049 ms
コンパイル使用メモリ 108,292 KB
実行使用メモリ 18,688 KB
最終ジャッジ日時 2024-12-23 01:42:39
合計ジャッジ時間 1,827 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

internal class Program
{
    public static void Main(string[] args)
    {
        var s = Console.ReadLine();
        List<string> parsing = new List<string>();
        List<char> token = new List<char>();

        int prev = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == '*' || s[i] == '+')
            {
                parsing.Add(s.Substring(prev, i - prev));
                token.Add(s[i]);
                prev = i + 1;
            }
        }
        if (token.Count == 0)
        {
            Console.WriteLine(s);
            return;
        }
        parsing.Add(s.Substring(prev, s.Length - prev));
        int[] nums = parsing.Select(int.Parse).ToArray();

        var current = nums[0];
        for (int i = 1; i < nums.Length; i++)
        {
            if (token[i - 1] == '*')
            {
                current = current + nums[i];
            }
            else
            {
                current = current * nums[i];                
            }
        }
        Console.WriteLine(current);
    }
}
0