結果
| 問題 |
No.205 マージして辞書順最小
|
| コンテスト | |
| ユーザー |
Shel_Rain
|
| 提出日時 | 2016-10-26 17:57:06 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,735 bytes |
| コンパイル時間 | 3,787 ms |
| コンパイル使用メモリ | 84,096 KB |
| 実行使用メモリ | 45,940 KB |
| 最終ジャッジ日時 | 2024-11-24 03:51:58 |
| 合計ジャッジ時間 | 7,201 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 |
| other | AC * 7 WA * 8 |
ソースコード
import java.util.*;
import java.util.Map.Entry;
public class DescOrder {
public static void main(String[] args) {
// 自分の得意な言語で
// Let's チャレンジ!!
Scanner sc = new Scanner(System.in);
String line = sc.nextLine();
List<String> input = new ArrayList<>();
int totalLength = 0;
for (int i = 0; i < Integer.parseInt(line); i ++) {
String str = sc.nextLine();
input.add(str);
totalLength += str.length();
}
Collections.sort(input);
Collections.reverse(input);
String result = "";
for (int i = 0; i < totalLength; i ++) {
String lastChar = getLastestChar(input);
if (lastChar != null) {
result += lastChar;
} else {
break;
}
}
// String reverseResult = new StringBuilder(result).reverse().toString();
System.out.println(result);
}
public static String getLastestChar(List<String> input) {
String result = null;
int deleteIndex = 0;
char str = 'z';
for (int i = 0; i < input.size(); i ++) {
if (!input.get(i).isEmpty()) {
String tmp = input.get(i);
if (tmp.substring(0,1).toCharArray()[0] <= str) {
str = tmp.substring(0,1).toCharArray()[0];
deleteIndex = i;
}
result = String.valueOf(str);
} else {
continue;
}
}
if (result != null) {
if (input.get(deleteIndex).length() == 1) {
input.remove(deleteIndex);
} else {
input.set(deleteIndex, input.get(deleteIndex).substring(1,input.get(deleteIndex).length()));
}
}
return result;
}
}
Shel_Rain