結果

問題 No.297 カードの数式
ユーザー 古寺いろは古寺いろは
提出日時 2016-02-01 18:22:27
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 59 ms / 1,000 ms
コード長 2,939 bytes
コンパイル時間 2,840 ms
コンパイル使用メモリ 107,756 KB
実行使用メモリ 22,900 KB
最終ジャッジ日時 2023-08-26 22:51:21
合計ジャッジ時間 4,992 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
18,744 KB
testcase_01 AC 53 ms
20,728 KB
testcase_02 AC 55 ms
20,708 KB
testcase_03 AC 56 ms
20,832 KB
testcase_04 AC 58 ms
20,784 KB
testcase_05 AC 54 ms
20,844 KB
testcase_06 AC 58 ms
20,780 KB
testcase_07 AC 55 ms
20,840 KB
testcase_08 AC 57 ms
22,716 KB
testcase_09 AC 57 ms
20,712 KB
testcase_10 AC 58 ms
20,932 KB
testcase_11 AC 59 ms
20,804 KB
testcase_12 AC 55 ms
18,752 KB
testcase_13 AC 55 ms
20,708 KB
testcase_14 AC 55 ms
20,780 KB
testcase_15 AC 58 ms
22,828 KB
testcase_16 AC 58 ms
22,728 KB
testcase_17 AC 58 ms
20,744 KB
testcase_18 AC 57 ms
20,716 KB
testcase_19 AC 58 ms
20,840 KB
testcase_20 AC 58 ms
20,736 KB
testcase_21 AC 56 ms
20,748 KB
testcase_22 AC 56 ms
20,804 KB
testcase_23 AC 59 ms
22,900 KB
testcase_24 AC 57 ms
20,800 KB
testcase_25 AC 56 ms
22,856 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
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());
    }

}
0