bufio.go 537 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package main
  2. import (
  3. "bufio"
  4. "io"
  5. "os"
  6. "strconv"
  7. )
  8. func main() {
  9. foo1()
  10. /*
  11. reader := bufio.NewReader(os.Stdin)
  12. var sum int
  13. for {
  14. line, _, err := reader.ReadLine()
  15. if err == io.EOF || len(line) == 0 {
  16. break
  17. }
  18. num, _ := strconv.Atoi(string(line))
  19. sum += num
  20. }
  21. io.WriteString(os.Stdout, strconv.Itoa(sum))
  22. */
  23. }
  24. func foo1() {
  25. scanner := bufio.NewScanner(os.Stdin)
  26. sum := 0
  27. for scanner.Scan() {
  28. a, _ := strconv.Atoi(scanner.Text())
  29. sum += a
  30. }
  31. io.WriteString(os.Stdout, strconv.Itoa(sum))
  32. }