package main import ( "bufio" "fmt" "os" "strconv" "strings" ) // エントリポイント func main() { in := bufio.NewScanner(os.Stdin) in.Scan() // 最初に○印が付いているカップの位置 input1 := in.Text() in.Scan() // カップを入れ替えた回数 input2 := in.Text() // 入れ替えるカップの位置番号 input3 := make([]string, 0) for in.Scan() { input3 = append(input3, in.Text()) } fmt.Println(shuffleGame(input1, input2, input3)) } // ○のついているカップの位置を特定する。 func shuffleGame(circleCupPos string, cupReplaceNum string, shuffleCupPos []string) string { _ = cupReplaceNum // カップ cup := [3]bool{} pos, _ := strconv.Atoi(circleCupPos) cup[pos-1] = true // 入れ替え for _, v := range shuffleCupPos { swaps := strings.Split(v, " ") i, _ := strconv.Atoi(swaps[0]) j, _ := strconv.Atoi(swaps[1]) swap(&cup, i-1, j-1) } // trueの番地を探す for i1, v2 := range cup { if v2 == true { return strconv.Itoa(i1 + 1) } } return "" } // 配列のi番目とj番目を入れ替える。 func swap(cup *[3]bool, i int, j int) { cup[i], cup[j] = cup[j], cup[i] }