結果
問題 | No.49 算数の宿題 |
ユーザー |
![]() |
提出日時 | 2015-10-31 20:48:36 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 31 ms / 5,000 ms |
コード長 | 1,467 bytes |
コンパイル時間 | 1,344 ms |
コンパイル使用メモリ | 108,032 KB |
実行使用メモリ | 19,200 KB |
最終ジャッジ日時 | 2024-12-23 01:46:48 |
合計ジャッジ時間 | 1,963 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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); } }