main.go 456 B

12345678910111213141516171819202122232425262728293031
  1. package main
  2. import (
  3. "bufio"
  4. "fmt"
  5. "os"
  6. "strconv"
  7. "strings"
  8. )
  9. func main() {
  10. input := bufio.NewScanner(os.Stdin)
  11. var output string
  12. for input.Scan() {
  13. line := input.Text()
  14. values := strings.Split(line, " ")
  15. num, _ := strconv.Atoi(values[1])
  16. output = reverseLeftWords(values[0], num)
  17. fmt.Println(output)
  18. }
  19. }
  20. func reverseLeftWords(s string, n int) string {
  21. if len(s) <= n {
  22. return s
  23. }
  24. var prefix = s[0:n]
  25. return s[n:] + prefix
  26. }