main.go 645 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 int
  12. var digits []int
  13. var target int
  14. for input.Scan() {
  15. line := input.Text()
  16. digits = []int{}
  17. values := strings.Split(line, " ")
  18. length := len(values)
  19. for index, v := range values {
  20. d, _ := strconv.Atoi(v)
  21. if index == length-1 {
  22. target = d
  23. break
  24. }
  25. digits = append(digits, d)
  26. }
  27. output = search(digits, target)
  28. fmt.Println(output)
  29. }
  30. }
  31. func search(nums []int, target int) int {
  32. var count int
  33. for _, v := range nums {
  34. if v == target {
  35. count++
  36. }
  37. }
  38. return count
  39. }