結果
問題 |
No.205 マージして辞書順最小
|
ユーザー |
![]() |
提出日時 | 2017-06-26 19:44:37 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 30 ms / 5,000 ms |
コード長 | 1,546 bytes |
コンパイル時間 | 800 ms |
コンパイル使用メモリ | 113,628 KB |
実行使用メモリ | 22,144 KB |
最終ジャッジ日時 | 2024-10-04 09:46:25 |
合計ジャッジ時間 | 1,868 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
コンパイルメッセージ
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.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); } }