Skip to content

Instantly share code, notes, and snippets.

@rabellamy
Created November 23, 2016 15:03
Show Gist options
  • Save rabellamy/b94fcb7fa4da3d12e9f184ae21fb6662 to your computer and use it in GitHub Desktop.
Save rabellamy/b94fcb7fa4da3d12e9f184ae21fb6662 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
)
func main() {
var n, d, index int
if _, err := fmt.Scan(&n, &d); err == nil {
if n >= 1 && n <= int(math.Pow(10, 5)) && d >= 1 && d <= n {
intergers := make([][]byte, n, n)
line := bufio.NewReader(os.Stdin)
nums, _ := line.ReadSlice('\n')
// Removes line feed character (10).
nums = nums[:len(nums)-1]
for _, num := range nums {
if num != 32 {
intergers[index] = append(intergers[index], num)
} else {
index++
}
}
for i := 1; i <= d; i++ {
var n []byte
n = intergers[0]
intergers = append(intergers[:0], intergers[1:]...)
intergers = append(intergers, n)
}
for delta, interger := range intergers {
if s, err := strconv.Atoi(string(interger)); err == nil {
if delta != len(intergers)-1 {
fmt.Printf("%v ", s)
} else {
fmt.Printf("%v\n", s)
}
}
}
} else {
fmt.Println("?")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment