백준문제풀이 5단계 문자열5 11720번 숫자의 합 (C#)

2024. 5. 20. 20:00백준 문제풀이/5단계 문자열

 

숫자 N개를 받고 주어진 숫자들의 합을 출력하는 문제

 

ex) intput : 5483 >  output : 20;

 

using System;
class BackJoon
{
    static void Main(string[] args)
    {
        string N = Console.ReadLine();
        string s = Console.ReadLine();
        int count = 0;
        for (int i = 0; i < s.Length; i++)
            count += int.Parse(s[i].ToString());
        Console.WriteLine(count.ToString());
    }
}

 

N은 필요없다 받아만주자.

 

받은 문자열 s를 하나씩 int.Parse해서 count에 누적해서 더헤주자.

그리고 count를 출력해주면 끝.