結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
41,492 KB
testcase_01 AC 134 ms
41,468 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 139 ms
41,788 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 203 ms
45,744 KB
testcase_11 AC 209 ms
45,984 KB
testcase_12 WA -
testcase_13 AC 206 ms
46,124 KB
testcase_14 AC 139 ms
41,868 KB
testcase_15 AC 132 ms
41,600 KB
testcase_16 AC 135 ms
41,488 KB
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

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



0