結果

問題 No.123 カードシャッフル
ユーザー sharkshark
提出日時 2017-07-16 23:10:57
言語 Go
(1.22.1)
結果
AC  
実行時間 428 ms / 5,000 ms
コード長 682 bytes
コンパイル時間 14,729 ms
コンパイル使用メモリ 231,840 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-04-16 22:39:06
合計ジャッジ時間 16,895 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 244 ms
6,016 KB
testcase_11 AC 428 ms
6,512 KB
testcase_12 AC 415 ms
6,508 KB
testcase_13 AC 419 ms
6,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main 

import ("fmt")

func main() {
    var sum, shf int
    fmt.Scan(&sum, &shf)
    cards := make([]int, sum)
    for i:=0; i<sum; i++ {
        cards[i] = 1 + i
    }
    
    for i:=0; i<shf; i++ {
        var whr int // 上から何番目か
        fmt.Scan(&whr)
        top := []int{cards[whr - 1]}
        //fmt.Println(top)
        cards = remove(cards, cards[whr-1])
        cards = append(top, cards...)
    } 
	fmt.Println(cards[0])
}

func remove(cards []int, card int) []int {
    result := []int{}
    for _, num := range cards {
        if num != card {
            result = append(result, num)
        }
    }
    //fmt.Println(result)
    return result
}
0