自測-5 Shuffling Machine(20 分)

Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing inadequate shuffles, many casinos employ automatic shuffling machines. Your task is to simulate a shuffling machine.
The machine shuffles a deck of 54 cards according to a given random order and repeats for a given number of times. It is assumed that the initial status of a card deck is in the following order:

S1, S2, ..., S13, 
H1, H2, ..., H13, 
C1, C2, ..., C13, 
D1, D2, ..., D13, 
J1, J2

where "S" stands for "Spade", "H" for "Heart", "C" for "Club", "D" for "Diamond", and "J" for "Joker". A given order is a permutation of distinct integers in [1, 54]. If the number at the i-th position is j, it means to move the card from position i to position j. For example, suppose we only have 5 cards: S3, H5, C1, D13 and J2. Given a shuffling order {4, 2, 5, 3, 1}, the result will be: J2, H5, D13, S3, C1. If we are to repeat the shuffling again, the result will be: C1, H5, S3, J2, D13.
Input Specification:

Each input file contains one test case. For each case, the first line contains a positive integer K (≤20) which is the number of repeat times. Then the next line contains the given order. All the numbers in a line are separated by a space.
Output Specification:

For each test case, print the shuffling results in one line. All the cards are separated by a space, and there must be no extra space at the end of the line.
Sample Input:

2
36 52 37 38 3 39 40 53 54 41 11 12 13 42 43 44 2 4 23 24 25 26 27 6 7 8 48 49 50 51 9 10 14 15 16 5 17 18 19 1 20 21 22 28 29 30 31 32 33 34 35 45 46 47

Sample Output:

S7 C11 C10 C12 S1 H7 H8 H9 D8 D9 S11 S12 S13 D10 D11 D12 S3 S4 S6 S10 H1 H2 C13 D2 D3 D4 H6 H3 D13 J1 J2 C1 C2 C3 C4 D1 S5 H5 H11 H12 C6 C7 C8 C9 S2 S8 S9 H10 D5 D6 D7 H4 H13 C5

作者: 陳越
單位: 浙江大學(xué)
時間限制: 400ms
內(nèi)存限制: 64MB
代碼長度限制: 16KB


import java.util.Scanner;

public class Main {
    public static String[] sort(int []seq,String []list) {
        String []New = new String[54];
        for (int j = 0; j < seq.length; j++) {
            New[seq[j]-1] = list[j];
        }
        return New;
    }
    public static void main(String[] args) {
        String []list = {
                "S1","S2","S3","S4","S5","S6","S7","S8","S9","S10","S11","S12","S13",
                "H1","H2","H3","H4","H5","H6","H7","H8","H9","H10","H11","H12","H13",
                "C1","C2","C3","C4","C5","C6","C7","C8","C9","C10","C11","C12","C13",
                "D1","D2","D3","D4","D5","D6","D7","D8","D9","D10","D11","D12","D13",
                "J1","J2"};
        Scanner in = new Scanner(System.in);
        int i = in.nextInt();
        int []seq = new int[54]; 
        for (int j = 0; j < 54; j++) {
            seq[j] = in.nextInt();
        }
        while(i>0) {
            list = sort(seq,list);
            i--;
        }
        for (int j = 0; j < list.length; j++) {
            System.out.print(list[j]+ " ");
        }
        System.out.println();
    }
}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末漏策,一起剝皮案震驚了整個濱河市洒试,隨后出現(xiàn)的幾起案子镰吆,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 212,383評論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件咆贬,死亡現(xiàn)場離奇詭異肄满,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)智政,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,522評論 3 385
  • 文/潘曉璐 我一進(jìn)店門认罩,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人续捂,你說我怎么就攤上這事垦垂。” “怎么了牙瓢?”我有些...
    開封第一講書人閱讀 157,852評論 0 348
  • 文/不壞的土叔 我叫張陵劫拗,是天一觀的道長。 經(jīng)常有香客問我矾克,道長页慷,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,621評論 1 284
  • 正文 為了忘掉前任胁附,我火速辦了婚禮酒繁,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘汉嗽。我一直安慰自己欲逃,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 65,741評論 6 386
  • 文/花漫 我一把揭開白布饼暑。 她就那樣靜靜地躺著稳析,像睡著了一般洗做。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上彰居,一...
    開封第一講書人閱讀 49,929評論 1 290
  • 那天诚纸,我揣著相機(jī)與錄音,去河邊找鬼陈惰。 笑死畦徘,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的抬闯。 我是一名探鬼主播井辆,決...
    沈念sama閱讀 39,076評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼溶握!你這毒婦竟也來了杯缺?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,803評論 0 268
  • 序言:老撾萬榮一對情侶失蹤睡榆,失蹤者是張志新(化名)和其女友劉穎萍肆,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體胀屿,經(jīng)...
    沈念sama閱讀 44,265評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡塘揣,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,582評論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了宿崭。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片亲铡。...
    茶點故事閱讀 38,716評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖劳曹,靈堂內(nèi)的尸體忽然破棺而出奴愉,到底是詐尸還是另有隱情,我是刑警寧澤铁孵,帶...
    沈念sama閱讀 34,395評論 4 333
  • 正文 年R本政府宣布锭硼,位于F島的核電站,受9級特大地震影響蜕劝,放射性物質(zhì)發(fā)生泄漏檀头。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 40,039評論 3 316
  • 文/蒙蒙 一岖沛、第九天 我趴在偏房一處隱蔽的房頂上張望暑始。 院中可真熱鬧,春花似錦婴削、人聲如沸廊镜。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,798評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽嗤朴。三九已至配椭,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間雹姊,已是汗流浹背股缸。 一陣腳步聲響...
    開封第一講書人閱讀 32,027評論 1 266
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留吱雏,地道東北人敦姻。 一個月前我還...
    沈念sama閱讀 46,488評論 2 361
  • 正文 我出身青樓,卻偏偏與公主長得像歧杏,于是被迫代替她去往敵國和親镰惦。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,612評論 2 350

推薦閱讀更多精彩內(nèi)容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,446評論 5 6
  • “金大師科技部落”公眾號開通了得滤,正趕上魔都的春天陨献,乍暖還寒。 一樹海棠星星點點懂更,幾處迎春搖曳生姿。陸家嘴世紀(jì)金融廣...
    濟(jì)千江閱讀 447評論 0 1
  • 不懂的事情很多急膀,到了不得不明白的時候沮协,雖然有一種被生活逼迫的無奈,過來之后發(fā)現(xiàn)也不過如此而已卓嫂。每個人都在說正能量慷暂,...
    曦萱閱讀 724評論 0 0