結果
問題 |
No.267 トランプソート
|
ユーザー |
![]() |
提出日時 | 2020-10-14 11:38:06 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 146 ms / 1,000 ms |
コード長 | 1,627 bytes |
コンパイル時間 | 2,524 ms |
コンパイル使用メモリ | 77,644 KB |
実行使用メモリ | 41,624 KB |
最終ジャッジ日時 | 2024-07-20 19:03:03 |
合計ジャッジ時間 | 6,838 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
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; } } }