結果
問題 | No.205 マージして辞書順最小 |
ユーザー |
|
提出日時 | 2019-09-28 16:34:07 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 820 ms / 5,000 ms |
コード長 | 1,773 bytes |
コンパイル時間 | 2,545 ms |
コンパイル使用メモリ | 80,376 KB |
実行使用メモリ | 55,760 KB |
最終ジャッジ日時 | 2024-10-02 10:48:07 |
合計ジャッジ時間 | 11,683 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
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(candidateIndex).matches("^"+str.get(i)+".*") && 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); } }