結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
40,028 KB
testcase_01 AC 132 ms
41,356 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 139 ms
41,276 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 197 ms
46,184 KB
testcase_11 AC 214 ms
45,580 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 136 ms
41,208 KB
testcase_15 AC 128 ms
41,344 KB
testcase_16 AC 127 ms
40,960 KB
testcase_17 WA -
testcase_18 AC 129 ms
41,144 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();
        }
        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) {
    		input.set(deleteIndex, input.get(deleteIndex).substring(1,input.get(deleteIndex).length()));
    	}
    	return result;
    }
    
}



0