結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
古寺いろは
|
| 提出日時 | 2016-02-01 18:22:27 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 1,000 ms |
| コード長 | 2,939 bytes |
| コンパイル時間 | 868 ms |
| コンパイル使用メモリ | 112,696 KB |
| 実行使用メモリ | 18,176 KB |
| 最終ジャッジ日時 | 2024-12-26 02:25:33 |
| 合計ジャッジ時間 | 2,406 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
コンパイルメッセージ
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;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class Meguru
{
public Meguru() { }
public static int Main()
{
new Meguru().calc();
return 0;
}
Scanner cin;
void calc()
{
cin = new Scanner();
int N = cin.nextInt();
List<int> num = new List<int>();
int plus = 0;
int minus = 0;
for (int i = 0; i < N; i++)
{
char c = cin.next()[0];
if (char.IsNumber(c))
{
num.Add(c - '0');
}
else if (c == '+') plus++;
else minus++;
}
num.Sort();
List<int> num2 = new List<int>(num);
long ansmax = 0;
for (int i = 0; i < minus; i++)
{
ansmax -= num2[0];
num2.RemoveAt(0);
}
for (int i = 0; i < plus; i++)
{
ansmax += num2[0];
num2.RemoveAt(0);
}
long add = 0;
for (int i = 0; i < num2.Count; i++)
{
add *= 10;
add += num2[num2.Count - 1 - i];
}
ansmax += add;
long ansmin = 0;
if (minus == 0)
{
num2 = new List<int>(num);
num2.Reverse();
long[] pow10 = new long[16];
pow10[0] = 1;
for (int i = 1; i < pow10.Length; i++)
{
pow10[i] = pow10[i - 1] * 10;
}
for (int i = 0; i < num2.Count; i++)
{
ansmin += num2[i] * pow10[i / (plus + 1)];
}
}
else
{
num2 = new List<int>(num);
for (int i = 0; i < plus + 1; i++)
{
ansmin += num2[0];
num2.RemoveAt(0);
}
for (int i = 0; i < minus - 1; i++)
{
ansmin -= num2[0];
num2.RemoveAt(0);
}
add = 0;
for (int i = 0; i < num2.Count; i++)
{
add *= 10;
add += num2[num2.Count - 1 - i];
}
ansmin -= add;
}
Console.WriteLine(ansmax + " " + ansmin);
}
}
class Scanner
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner()
{
s = new string[0];
i = 0;
}
public string next()
{
if (i < s.Length) return s[i++];
string st = Console.ReadLine();
while (st == "") st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next();
}
public int nextInt()
{
return int.Parse(next());
}
public long nextLong()
{
return long.Parse(next());
}
public double nextDouble()
{
return double.Parse(next());
}
}
古寺いろは