結果
問題 |
No.49 算数の宿題
|
ユーザー |
![]() |
提出日時 | 2018-10-08 09:45:24 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 28 ms / 5,000 ms |
コード長 | 639 bytes |
コンパイル時間 | 1,031 ms |
コンパイル使用メモリ | 103,680 KB |
実行使用メモリ | 17,920 KB |
最終ジャッジ日時 | 2024-12-23 02:00:21 |
合計ジャッジ時間 | 2,014 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.Collections.Generic; using System; public class Hello { public static void Main() { var s = Console.ReadLine().Trim(); string[] line = s.Split('*', '+'); var a = Array.ConvertAll(line, int.Parse); var b = new List<char>(); foreach (var x in s) if (x == '+') b.Add('m'); else if (x == '*') b.Add('p'); int ans; if (b[0] == 'm') ans = a[0] * a[1]; else ans = a[0] + a[1]; for (int i = 2; i < a.Length; i++) if (b[i - 1] == 'm') ans *= a[i]; else ans += a[i]; Console.WriteLine(ans); } }