結果

問題 No.267 トランプソート
ユーザー tentententen
提出日時 2020-10-14 11:38:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 1,000 ms
コード長 1,627 bytes
コンパイル時間 1,779 ms
コンパイル使用メモリ 74,868 KB
実行使用メモリ 57,656 KB
最終ジャッジ日時 2023-09-28 00:32:03
合計ジャッジ時間 5,986 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
56,132 KB
testcase_01 AC 114 ms
54,068 KB
testcase_02 AC 110 ms
55,796 KB
testcase_03 AC 108 ms
56,032 KB
testcase_04 AC 117 ms
55,908 KB
testcase_05 AC 116 ms
55,732 KB
testcase_06 AC 106 ms
56,008 KB
testcase_07 AC 108 ms
54,480 KB
testcase_08 AC 114 ms
55,880 KB
testcase_09 AC 115 ms
55,644 KB
testcase_10 AC 116 ms
55,716 KB
testcase_11 AC 114 ms
56,016 KB
testcase_12 AC 114 ms
55,636 KB
testcase_13 AC 117 ms
55,736 KB
testcase_14 AC 112 ms
55,876 KB
testcase_15 AC 113 ms
56,072 KB
testcase_16 AC 137 ms
55,868 KB
testcase_17 AC 134 ms
55,872 KB
testcase_18 AC 118 ms
57,656 KB
testcase_19 AC 115 ms
53,536 KB
testcase_20 AC 123 ms
55,560 KB
testcase_21 AC 117 ms
55,728 KB
testcase_22 AC 115 ms
55,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	Card[] cards = new Card[n];
    	for (int i = 0; i < n; i++) {
    	    cards[i] = new Card(sc.next());
    	}
    	Arrays.sort(cards);
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < n; i++) {
    	    if (i > 0) {
    	        sb.append(" ");
    	    }
    	    sb.append(cards[i]);
    	}
    	System.out.println(sb);
	}
	
	static class Card implements Comparable<Card> {
	    String name;
	    char suite;
	    int mark;
	    int value;
	    static char[] marks = new char[]{'D', 'C', 'H', 'S'};
	    
	    
	    public Card(String name) {
	        this.name = name;
	        suite = name.charAt(0);
	        for (int i = 0; i < marks.length; i++) {
	            if (marks[i] == suite) {
	                mark = i;
	                break;
	            }
	        }
	        char tmp = name.charAt(1);
	        if (tmp == 'A') {
	            value = 1;
	        } else if (tmp == 'J') {
	            value = 11;
	        } else if (tmp == 'T') {
	            value = 10;
	        } else if (tmp == 'Q') {
	            value = 12;
	        } else if (tmp == 'K') {
	            value = 13;
	        } else {
	            value = tmp - '0';
	        }
	    }
	    
	    public int compareTo(Card another) {
	        if (mark == another.mark) {
	            return value - another.value;
	        } else {
	            return mark - another.mark;
	        }
	    }
	    
	    public String toString() {
	        
	        return name;
	    }
	}
}
0