結果

問題 No.267 トランプソート
ユーザー ぴろずぴろず
提出日時 2015-08-21 22:29:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 1,000 ms
コード長 1,465 bytes
コンパイル時間 2,373 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 56,032 KB
最終ジャッジ日時 2023-09-25 14:45:26
合計ジャッジ時間 6,343 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,720 KB
testcase_01 AC 127 ms
55,712 KB
testcase_02 AC 124 ms
56,032 KB
testcase_03 AC 125 ms
55,844 KB
testcase_04 AC 127 ms
53,560 KB
testcase_05 AC 125 ms
55,916 KB
testcase_06 AC 124 ms
55,932 KB
testcase_07 AC 127 ms
55,836 KB
testcase_08 AC 133 ms
55,796 KB
testcase_09 AC 132 ms
55,600 KB
testcase_10 AC 132 ms
55,728 KB
testcase_11 AC 131 ms
55,420 KB
testcase_12 AC 133 ms
55,676 KB
testcase_13 AC 132 ms
55,324 KB
testcase_14 AC 133 ms
55,716 KB
testcase_15 AC 135 ms
55,424 KB
testcase_16 AC 134 ms
55,704 KB
testcase_17 AC 135 ms
55,840 KB
testcase_18 AC 136 ms
55,344 KB
testcase_19 AC 137 ms
55,808 KB
testcase_20 AC 139 ms
55,596 KB
testcase_21 AC 135 ms
55,636 KB
testcase_22 AC 134 ms
55,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no267;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Card[] c = new Card[n];
		for(int i=0;i<n;i++) {
			c[i] = Card.valueOf(sc.next());
		}
		Arrays.sort(c);
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<n;i++) {
			if (i > 0) {
				sb.append(' ');
			}
			sb.append(c[i]);
		}
		System.out.println(sb);
	}

	public static class Card implements Comparable<Card>{
		String str;
		int number;
		char suit;
		public Card(String s,int num,char suit) {
			this.str = s;
			this.number = num;
			this.suit = suit;
		}
		public static Card valueOf(String s) {
			return new Card(s,g(s.substring(1, s.length())),s.charAt(0));
		}
		@Override
		public int compareTo(Card o) {
			if (suit != o.suit) {
				return Integer.compare(f(suit), f(o.suit));
			}
			return Integer.compare(number, o.number);
		}
		private static int f(char s) {
			if (s == 'D') {
				return 0;
			}
			if (s == 'C') {
				return 1;
			}
			if (s == 'H') {
				return 2;
			}
			return 3;
		}
		private static int g(String s) {
			try {
				return Integer.valueOf(s);
			} catch (Exception e) {
				switch (s) {
				case "A":
					return 1;
				case "T":
					return 10;
				case "J":
					return 11;
				case "Q":
					return 12;
				case "K":
					return 13;
				}
			}
			return -1;
		}
		public String toString() {
			return str;
		}
	}

}
0