結果

問題 No.205 マージして辞書順最小
ユーザー mbanmban
提出日時 2017-06-26 19:44:37
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 1,546 bytes
コンパイル時間 1,020 ms
コンパイル使用メモリ 111,772 KB
実行使用メモリ 30,152 KB
最終ジャッジ日時 2024-04-15 01:56:32
合計ジャッジ時間 2,232 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
23,404 KB
testcase_01 AC 24 ms
23,728 KB
testcase_02 AC 25 ms
25,820 KB
testcase_03 AC 25 ms
23,664 KB
testcase_04 AC 25 ms
25,692 KB
testcase_05 AC 24 ms
23,532 KB
testcase_06 AC 23 ms
23,636 KB
testcase_07 AC 29 ms
27,732 KB
testcase_08 AC 28 ms
30,152 KB
testcase_09 AC 27 ms
27,984 KB
testcase_10 AC 39 ms
27,856 KB
testcase_11 AC 34 ms
25,808 KB
testcase_12 AC 31 ms
27,728 KB
testcase_13 AC 28 ms
29,900 KB
testcase_14 AC 23 ms
23,792 KB
testcase_15 AC 22 ms
21,944 KB
testcase_16 AC 24 ms
23,596 KB
testcase_17 AC 24 ms
23,760 KB
testcase_18 AC 24 ms
25,576 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.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int N;
    private string[] S;
    private int Length = 0;

    private void Scan()
    {
        N = int.Parse(Console.ReadLine());
        S = new string[N];
        for (int i = 0; i < N; i++)
        {
            string line = Console.ReadLine();
            Length += line.Length;
            S[i] = line + (char)('z' + 1);
        }
    }

    private int Compare(string a, string b)
    {
        int l = Math.Min(a.Length, b.Length);
        for (int i = 0; i < l; i++)
        {
            if (a[i] > b[i])
            {
                return 1;
            }
            if (a[i] < b[i])
            {
                return -1;
            }
        }
        return a.Length.CompareTo(b.Length);
    }

    public void Solve()
    {
        Scan();
        string ans = "";
        for (int i = 0; i < Length; i++)
        {
            int index = 0;
            string min = S[0];
            for (int j = 1; j < N; j++)
            {

                if (Compare(min,S[j]) > 0)
                {
                    min = S[j];
                    index = j;
                }
            }
            ans += min[0];
            S[index] = min.Substring(1);
        }
        Console.WriteLine(ans);
    }
}
0