結果
問題 |
No.297 カードの数式
|
ユーザー |
![]() |
提出日時 | 2015-11-07 00:20:54 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,391 bytes |
コンパイル時間 | 4,113 ms |
コンパイル使用メモリ | 111,476 KB |
実行使用メモリ | 29,320 KB |
最終ジャッジ日時 | 2024-09-13 13:21:27 |
合計ジャッジ時間 | 3,019 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | WA * 19 RE * 4 |
コンパイルメッセージ
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; using System.Text; using System.Threading.Tasks; namespace Yuki { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(); int p = s.Where(x => x.Equals("+")).Count(); int m = s.Where(x => x.Equals("-")).Count(); int k = n - p - m; int[] a = new int[k]; int b; int j = 0; for (int i = 0; i < n; i++) { if (int.TryParse(s[i], out b) || s[i] == "0") { a[j] = b; j++; } } Array.Sort(a); //max string st = ""; for (int i = a.Length - 1; i > m + p - 1; i--) { st += a[i].ToString(); } int max = int.Parse(st); for (int i = 0; i < p + m; i++) { if (i < m) { max = max - a[i]; } else { max = max + a[i]; } } Console.WriteLine(max); Console.WriteLine("-" + max.ToString()); } } }