結果
問題 | No.205 マージして辞書順最小 |
ユーザー | Shel_Rain |
提出日時 | 2016-10-26 19:11:30 |
言語 | Java19 (openjdk 21) |
結果 |
AC
|
実行時間 | 249 ms / 5,000 ms |
コード長 | 1,964 bytes |
コンパイル時間 | 3,862 ms |
コンパイル使用メモリ | 87,124 KB |
実行使用メモリ | 60,920 KB |
最終ジャッジ日時 | 2023-08-15 19:26:52 |
合計ジャッジ時間 | 8,317 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 127 ms
55,736 KB |
testcase_01 | AC | 125 ms
55,316 KB |
testcase_02 | AC | 199 ms
58,752 KB |
testcase_03 | AC | 204 ms
58,716 KB |
testcase_04 | AC | 200 ms
58,900 KB |
testcase_05 | AC | 196 ms
59,044 KB |
testcase_06 | AC | 138 ms
56,136 KB |
testcase_07 | AC | 229 ms
59,896 KB |
testcase_08 | AC | 226 ms
59,520 KB |
testcase_09 | AC | 226 ms
60,260 KB |
testcase_10 | AC | 246 ms
60,748 KB |
testcase_11 | AC | 249 ms
60,364 KB |
testcase_12 | AC | 239 ms
60,920 KB |
testcase_13 | AC | 222 ms
60,432 KB |
testcase_14 | AC | 136 ms
55,484 KB |
testcase_15 | AC | 123 ms
54,096 KB |
testcase_16 | AC | 128 ms
55,476 KB |
testcase_17 | AC | 129 ms
55,476 KB |
testcase_18 | AC | 127 ms
55,872 KB |
ソースコード
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(); if (str.length() < 50) { for (int j = 0; j < 50 - str.length(); j ++) { str += "|"; } } 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 = -1; char str = 'z'; int onlyOneChar = 0; 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] == '|') { continue; } if (tmp.substring(0,1).toCharArray()[0] < str || deleteIndex == -1) { str = tmp.substring(0,1).toCharArray()[0]; deleteIndex = i; } result = String.valueOf(str); } else { continue; } } if (result != null) { String newStr = input.get(deleteIndex).substring(1,input.get(deleteIndex).length()) + "|"; input.set(deleteIndex, newStr); Collections.sort(input); } return result; } }