結果

問題 No.267 トランプソート
ユーザー yun_appyun_app
提出日時 2016-05-13 13:19:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 75 ms / 1,000 ms
コード長 2,406 bytes
コンパイル時間 2,568 ms
コンパイル使用メモリ 81,116 KB
実行使用メモリ 51,044 KB
最終ジャッジ日時 2024-04-15 15:29:09
合計ジャッジ時間 5,028 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
50,960 KB
testcase_01 AC 66 ms
50,588 KB
testcase_02 AC 66 ms
50,504 KB
testcase_03 AC 68 ms
50,412 KB
testcase_04 AC 67 ms
50,744 KB
testcase_05 AC 66 ms
50,948 KB
testcase_06 AC 66 ms
50,664 KB
testcase_07 AC 65 ms
50,756 KB
testcase_08 AC 65 ms
50,736 KB
testcase_09 AC 73 ms
50,888 KB
testcase_10 AC 68 ms
51,044 KB
testcase_11 AC 67 ms
50,740 KB
testcase_12 AC 66 ms
50,588 KB
testcase_13 AC 71 ms
50,428 KB
testcase_14 AC 72 ms
50,860 KB
testcase_15 AC 67 ms
50,376 KB
testcase_16 AC 68 ms
50,844 KB
testcase_17 AC 67 ms
50,856 KB
testcase_18 AC 71 ms
50,596 KB
testcase_19 AC 66 ms
50,672 KB
testcase_20 AC 69 ms
50,828 KB
testcase_21 AC 66 ms
50,352 KB
testcase_22 AC 75 ms
50,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] lines = br.readLine().split(" ");
        ArrayList<Trump> trumps = new ArrayList<Trump>();
        for(String st:lines){
            trumps.add(new Trump(st));
        }
        Collections.sort(trumps,(a,b)->{return a.compare(b);});
        StringBuilder sb = new StringBuilder();
        for(Trump trump:trumps){
            if(sb.length()!=0){
                sb.append(" ");
            }
            sb.append(trump.toString());
        }
        System.out.println(sb);
    }
    
    
    public static class Trump{
        public int mark;   //D:0,C:1,H:2,S:3
        public int number; //A:1,T:10,J:11,Q:12,K:13
        public String str;
        public Trump(String st){
            this.str = st;
            char c1 = st.charAt(0);
            switch(c1){
            case 'D':
                mark = 0;
                break;
            case 'C':
                mark = 1;
                break;
            case 'H':
                mark = 2;
                break;
            case 'S':
                mark = 3;
                break;
            default:
                break;
            }
            char c2 = st.charAt(1);
            switch(c2){
            case 'A':
                number = 1;
                break;
            case 'T':
                number = 10;
                break;
            case 'J':
                number = 11;
                break;
            case 'Q':
                number = 12;
                break;
            case 'K':
                number = 13;
                break;
            default:
                number = (int)(c2-'0');
                break;
            }
        }
        public int compare(Trump other){
            if(this.mark != other.mark){
                return this.mark - other.mark;
            }else{
                return this.number - other.number;
            }
        }
        public String toString(){
            return this.str;
        }
    }
}
0