結果

問題 No.205 マージして辞書順最小
ユーザー PG-practicePG-practice
提出日時 2019-09-28 15:48:18
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,714 bytes
コンパイル時間 2,114 ms
コンパイル使用メモリ 79,768 KB
実行使用メモリ 62,016 KB
最終ジャッジ日時 2024-04-10 07:30:29
合計ジャッジ時間 8,110 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
54,244 KB
testcase_01 AC 120 ms
53,872 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 151 ms
53,916 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 170 ms
57,364 KB
testcase_11 AC 381 ms
59,316 KB
testcase_12 WA -
testcase_13 AC 402 ms
59,116 KB
testcase_14 AC 118 ms
53,220 KB
testcase_15 AC 121 ms
54,500 KB
testcase_16 AC 137 ms
54,396 KB
testcase_17 AC 140 ms
54,320 KB
testcase_18 AC 140 ms
54,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
//mport java.io.*;

// class MyComparator implements Comparator<String>{
//     @Override
//     int compare(String str1,String str2){
        
//     }
// }

public class Main{

    static int INFTY = Integer.MAX_VALUE;
    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());
            int n= sc.nextInt();
            sc.nextLine();
            String T = "";
            List<String> str = new LinkedList<>();

            for(int i=0;i<n;i++){
                String tmp = sc.nextLine();
                if(!tmp.equals("")){
                    str.add(tmp);
                }
            }
            
            while(true){
                int candidateIndex=0;
                if(str.size()==1 && str.get(0).equals("")){
                    break;
                }
                for(int i=0;i<str.size();i++){
                    if(str.get(i).length()==0){
                        str.remove(i);
                        i--;
                        continue;
                    }
                    if(str.get(i).compareTo(str.get(candidateIndex))<=0 || str.get(i).matches("^"+str.get(candidateIndex)+".*")){
                        candidateIndex=i;
                    }   
                }
                T += str.get(candidateIndex).substring(0,1);
                
                str.set(candidateIndex,str.get(candidateIndex).substring(1,str.get(candidateIndex).length()));
            }
            System.out.println(T);
                
            }
}
0