結果

問題 No.267 トランプソート
ユーザー yun_app
提出日時 2016-05-13 13:19:12
言語 Java
(openjdk 23)
結果
AC  
実行時間 59 ms / 1,000 ms
コード長 2,406 bytes
コンパイル時間 2,293 ms
コンパイル使用メモリ 91,524 KB
実行使用メモリ 50,808 KB
最終ジャッジ日時 2024-10-05 14:17:34
合計ジャッジ時間 4,497 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

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