結果

問題 No.267 トランプソート
ユーザー tentententen
提出日時 2022-07-29 16:05:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 47 ms / 1,000 ms
コード長 1,944 bytes
コンパイル時間 2,323 ms
コンパイル使用メモリ 76,108 KB
実行使用メモリ 50,108 KB
最終ジャッジ日時 2023-09-26 12:54:21
合計ジャッジ時間 4,625 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,504 KB
testcase_01 AC 43 ms
49,632 KB
testcase_02 AC 43 ms
49,620 KB
testcase_03 AC 44 ms
49,808 KB
testcase_04 AC 44 ms
49,416 KB
testcase_05 AC 44 ms
49,408 KB
testcase_06 AC 44 ms
49,808 KB
testcase_07 AC 44 ms
49,548 KB
testcase_08 AC 44 ms
47,772 KB
testcase_09 AC 45 ms
49,976 KB
testcase_10 AC 45 ms
49,776 KB
testcase_11 AC 45 ms
49,600 KB
testcase_12 AC 45 ms
49,640 KB
testcase_13 AC 45 ms
49,620 KB
testcase_14 AC 44 ms
49,496 KB
testcase_15 AC 44 ms
49,636 KB
testcase_16 AC 47 ms
49,556 KB
testcase_17 AC 46 ms
49,612 KB
testcase_18 AC 45 ms
49,568 KB
testcase_19 AC 45 ms
49,684 KB
testcase_20 AC 45 ms
49,532 KB
testcase_21 AC 45 ms
50,108 KB
testcase_22 AC 45 ms
49,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static HashMap<Character, Integer> change = new HashMap<>();
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        String order = "A23456789TJQKDCHS";
        int idx = 0;
        for (char c : order.toCharArray()) {
            change.put(c, idx++);
        }
        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;
        int value;
        
        public Card(String name) {
            this.name = name;
            value = change.get(name.charAt(0)) * 20 + change.get(name.charAt(1));
        }
        
        public int compareTo(Card another) {
            return value - another.value;
        }
        
        public String toString() {
            return name;
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0