結果

問題 No.267 トランプソート
ユーザー jp_stejp_ste
提出日時 2016-05-11 15:07:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 166 ms / 1,000 ms
コード長 2,629 bytes
コンパイル時間 2,903 ms
コンパイル使用メモリ 84,048 KB
実行使用メモリ 54,672 KB
最終ジャッジ日時 2024-04-15 15:09:45
合計ジャッジ時間 7,488 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
54,284 KB
testcase_01 AC 153 ms
54,388 KB
testcase_02 AC 156 ms
54,592 KB
testcase_03 AC 148 ms
54,556 KB
testcase_04 AC 149 ms
54,460 KB
testcase_05 AC 149 ms
54,532 KB
testcase_06 AC 147 ms
54,140 KB
testcase_07 AC 153 ms
54,284 KB
testcase_08 AC 160 ms
54,440 KB
testcase_09 AC 158 ms
54,160 KB
testcase_10 AC 160 ms
54,156 KB
testcase_11 AC 165 ms
54,532 KB
testcase_12 AC 160 ms
54,472 KB
testcase_13 AC 166 ms
54,316 KB
testcase_14 AC 159 ms
54,420 KB
testcase_15 AC 159 ms
54,476 KB
testcase_16 AC 161 ms
54,420 KB
testcase_17 AC 160 ms
54,476 KB
testcase_18 AC 160 ms
54,436 KB
testcase_19 AC 161 ms
54,364 KB
testcase_20 AC 160 ms
54,672 KB
testcase_21 AC 158 ms
54,252 KB
testcase_22 AC 162 ms
54,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner scan = new Scanner(System.in)) {
            int n = Integer.parseInt(scan.next());
            ArrayList<Integer> D = new ArrayList<>();
            ArrayList<Integer> C = new ArrayList<>();
            ArrayList<Integer> H = new ArrayList<>();
            ArrayList<Integer> S = new ArrayList<>();
            
            for(int i=0; i<n; i++) {
                String v = scan.next();
                if(v.charAt(0) == 'D') {
                    D.add(toNumber(v.charAt(1)));
                } else if(v.charAt(0) == 'C') {
                    C.add(toNumber(v.charAt(1)));
                } else if(v.charAt(0) == 'H') {
                    H.add(toNumber(v.charAt(1))); 
                } else if(v.charAt(0) == 'S') {
                    S.add(toNumber(v.charAt(1)));
                }
            }
            
            Collections.sort(D);
            Collections.sort(C);
            Collections.sort(H);
            Collections.sort(S);
            
            ArrayList<String> list = new ArrayList<>();
            for(int i=0; i<D.size(); i++) {
                list.add("D"+toChar(D.get(i)));
            }
            for(int i=0; i<C.size(); i++) {
                list.add("C"+toChar(C.get(i)));
            }
            for(int i=0; i<H.size(); i++) {
                list.add("H"+toChar(H.get(i)));
            }
            for(int i=0; i<S.size(); i++) {
                list.add("S"+toChar(S.get(i)));
            }
            
            for(int i=0; i<list.size(); i++) {
                if(i > 0) System.out.print(" ");
                System.out.print(list.get(i));
            }
        }
    }
    
    static int toNumber(char c) {
        int ret = 0;
        if(c >= '2' && c <= '9') {
            ret = c - '0';
        } else if(c == 'A') {
            ret = 1; 
        } else if(c == 'T') {
            ret = 10;
        } else if(c == 'J') {
            ret = 11;
        } else if(c == 'Q') {
            ret = 12;
        } else if(c == 'K') {
            ret = 13;
        }
        return ret;
    }
    
    static char toChar(int i) {
        char c = '0';
        if(i >= 2 && i <= 9) {
            c = (char)(i + '0');
        } else if(i == 1) {
            c = 'A';
        } else if(i == 10) {
            c = 'T';
        } else if(i == 11) {
            c = 'J';
        } else if(i == 12) {
            c = 'Q'; 
        } else if(i == 13) {
            c = 'K';
        }
        return c;
    }
}
0