utils.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package main
  2. import (
  3. "bufio"
  4. "strconv"
  5. "strings"
  6. )
  7. // Pair ...
  8. type Pair struct {
  9. _1 int
  10. _2 int
  11. }
  12. // Pair64 ...
  13. type Pair64 struct {
  14. _1 int64
  15. _2 int64
  16. }
  17. // ReadLine ...
  18. func ReadLine(s *bufio.Scanner) string {
  19. s.Scan()
  20. return s.Text()
  21. }
  22. // ReadInt ...
  23. func ReadInt(s *bufio.Scanner) int {
  24. s.Scan()
  25. i, _ := strconv.ParseInt(s.Text(), 10, 32)
  26. return int(i)
  27. }
  28. // ReadInt64 ...
  29. func ReadInt64(s *bufio.Scanner) int64 {
  30. s.Scan()
  31. i, _ := strconv.ParseInt(s.Text(), 10, 64)
  32. return i
  33. }
  34. // ReadInts ...
  35. func ReadInts(s *bufio.Scanner) []int {
  36. s.Scan()
  37. strs := strings.Split(s.Text(), " ")
  38. nums := make([]int, len(strs))
  39. for i, str := range strs {
  40. num, _ := strconv.ParseInt(str, 10, 32)
  41. nums[i] = int(num)
  42. }
  43. return nums
  44. }
  45. // ReadInt64s ...
  46. func ReadInt64s(s *bufio.Scanner) []int64 {
  47. s.Scan()
  48. strs := strings.Split(s.Text(), " ")
  49. nums := make([]int64, len(strs))
  50. for i, str := range strs {
  51. num, _ := strconv.ParseInt(str, 10, 64)
  52. nums[i] = num
  53. }
  54. return nums
  55. }
  56. func maxInt(x, y int) int {
  57. if y < x {
  58. return x
  59. }
  60. return y
  61. }