結果

問題 No.267 トランプソート
ユーザー htensaihtensai
提出日時 2019-11-23 15:27:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 1,000 ms
コード長 1,462 bytes
コンパイル時間 2,705 ms
コンパイル使用メモリ 78,212 KB
実行使用メモリ 42,128 KB
最終ジャッジ日時 2024-04-19 14:42:12
合計ジャッジ時間 5,785 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
41,700 KB
testcase_01 AC 104 ms
41,548 KB
testcase_02 AC 114 ms
42,036 KB
testcase_03 AC 114 ms
41,316 KB
testcase_04 AC 105 ms
42,128 KB
testcase_05 AC 102 ms
41,548 KB
testcase_06 AC 104 ms
41,740 KB
testcase_07 AC 104 ms
41,548 KB
testcase_08 AC 120 ms
41,304 KB
testcase_09 AC 107 ms
41,916 KB
testcase_10 AC 117 ms
41,964 KB
testcase_11 AC 120 ms
41,644 KB
testcase_12 AC 110 ms
41,656 KB
testcase_13 AC 108 ms
41,604 KB
testcase_14 AC 121 ms
41,708 KB
testcase_15 AC 116 ms
41,548 KB
testcase_16 AC 121 ms
41,308 KB
testcase_17 AC 117 ms
41,440 KB
testcase_18 AC 123 ms
41,380 KB
testcase_19 AC 120 ms
41,728 KB
testcase_20 AC 117 ms
41,916 KB
testcase_21 AC 119 ms
41,608 KB
testcase_22 AC 108 ms
41,520 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[] arr = new Card[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = new Card(sc.next());
		}
		Arrays.sort(arr);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    if (i != 0) {
		        sb.append(" ");
		    }
		    sb.append(arr[i]);
		}
		System.out.println(sb);
	}
	
	static class Card implements Comparable<Card> {
	    String card;
	    char mark;
	    char number;
	    int value;
	    public Card(String card) {
	        this.card = card;
	        mark = card.charAt(0);
	        number = card.charAt(1);
	        if (number >= '2' && number <= '9') {
	            value = number - '0';
	        } else if (number == 'A') {
	            value = 1;
	        } else if (number == 'T') {
	            value = 10;
	        } else if (number == 'J') {
	            value = 11;
	        } else if (number == 'Q') {
	            value = 12;
	        } else if (number == 'K') {
	            value = 13;
	        }
	        if (mark == 'C') {
	            value += 100;
	        } else if (mark == 'H') {
	            value += 200;
	        } else if (mark == 'S') {
	            value += 300;
	        }
	    }
	    
	    public int compareTo(Card another) {
	        return value - another.value;
	    }
	    
	    public String toString() {
	        return card;
	    }
	}
}
0