Go
package main
import (
"fmt"
"sort"
"strings"
)
type myItem struct {
index int
value int
}
func reflushMap(list []*myItem, value int) []*myItem {
newList := make([]*myItem, 0)
startIndex := 1
for i, item := range list {
if item.value == value {
for _, m := range list[i+1:] {
m.value = startIndex
startIndex++
newList = append(newList, m)
}
for _, m := range list[:i] {
m.value = startIndex
startIndex++
newList = append(newList, m)
}
break
}
}
return newList
}
func main() {
var M int
fmt.Scan(&M)
oldList := make([]*myItem, 0)
for i := 1; i <= 100; i++ {
oldList = append(oldList, &myItem{
index: i,
value: i,
})
}
indexStrs := make([]string, 0)
for {
oldList = reflushMap(oldList, M)
if len(oldList) < M {
indexs := make([]int, 0)
for _, item := range oldList {
indexs = append(indexs, item.index)
}
sort.Ints(indexs)
for _, item := range indexs {
indexStrs = append(indexStrs, fmt.Sprintf("%d", item))
}
break
}
}
fmt.Println(strings.Join(indexStrs, ","))
}