結果
問題 |
No.205 マージして辞書順最小
|
ユーザー |
|
提出日時 | 2019-09-28 15:26:51 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,706 bytes |
コンパイル時間 | 2,329 ms |
コンパイル使用メモリ | 80,420 KB |
実行使用メモリ | 57,632 KB |
最終ジャッジ日時 | 2024-10-02 08:30:56 |
合計ジャッジ時間 | 6,422 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 6 WA * 9 |
ソースコード
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).contains(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); } }