Skip to content

Instantly share code, notes, and snippets.

@gerep
Last active March 15, 2017 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerep/6e8b7c9af5debf16c56b85d7337dc3bb to your computer and use it in GitHub Desktop.
Save gerep/6e8b7c9af5debf16c56b85d7337dc3bb to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
var lines [2]string
var count int
for scanner.Scan() {
lines[count] = scanner.Text()
count++
}
if err := scanner.Err(); err != nil {
panic(err)
}
size := string(lines[0])
numbers := strings.Split(string(lines[1]), " ")
intSize, err := strconv.Atoi(size)
if err != nil {
panic(err)
}
var total int
for x := 0; x < intSize; x++ {
intNumber, err := strconv.Atoi(numbers[x])
if err != nil {
panic(err)
}
total += intNumber
}
fmt.Println(total)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment