Home 백준 숫자의 합 11720
Post
Cancel

백준 숫자의 합 11720

백준 11720 알고리즘

https://www.acmicpc.net/problem/11720

"11720"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	r := bufio.NewScanner(os.Stdin)

	var n int
	fmt.Scanln(&n)

	r.Scan()
	splits := strings.Split(r.Text(), "")
	var result int = 0
	for i := 0; i < len(splits); i++ {
		num, _ := strconv.Atoi(splits[i])
		result += num
	}

	fmt.Fprintln(w, result)
}

This post is licensed under CC BY 4.0 by the author.