結果

問題 No.205 マージして辞書順最小
ユーザー Shel_RainShel_Rain
提出日時 2016-10-26 19:07:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,823 bytes
コンパイル時間 3,978 ms
コンパイル使用メモリ 84,148 KB
実行使用メモリ 57,324 KB
最終ジャッジ日時 2024-05-03 06:12:00
合計ジャッジ時間 8,519 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
41,220 KB
testcase_01 AC 138 ms
41,244 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 144 ms
41,228 KB
testcase_07 AC 236 ms
46,920 KB
testcase_08 AC 234 ms
46,952 KB
testcase_09 AC 231 ms
46,992 KB
testcase_10 AC 259 ms
48,148 KB
testcase_11 AC 251 ms
47,472 KB
testcase_12 AC 246 ms
46,684 KB
testcase_13 AC 226 ms
47,752 KB
testcase_14 AC 149 ms
41,748 KB
testcase_15 AC 135 ms
41,452 KB
testcase_16 AC 134 ms
41,488 KB
testcase_17 AC 134 ms
41,164 KB
testcase_18 AC 135 ms
41,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = -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;
    }
    
}
0