![[백준 / BOJ] 11720번 숫자의 합 (C++, Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fbxnn9A%2FbtrJm80KiM2%2Fjbu3bGuNKz4B9D8wx4VMhk%2Fimg.png)
[백준 / BOJ] 11720번 숫자의 합 (C++, Python)◎ 자료구조와 알고리즘/백준(BOJ) 문제풀이2022. 1. 17. 08:09
Table of Contents
반응형
링크 : https://www.acmicpc.net/problem/11720
11720번: 숫자의 합
첫째 줄에 숫자의 개수 N (1 ≤ N ≤ 100)이 주어진다. 둘째 줄에 숫자 N개가 공백없이 주어진다.
www.acmicpc.net
문제

문제 풀이
이전 문제에서 활용했던 아스키 코드를 사용해야 한다. 파이썬은 내장함수로 해결 가능하다.
C++ 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int N, res = 0; // 숫자의 개수, 결괏값 | |
char num; | |
cin >> N; | |
for (int i = 0; i < N; i++) | |
{ | |
cin >> num; | |
res += num - 48; | |
} | |
cout << res; | |
return 0; | |
} |
Python 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = int(input()) | |
print(sum(map(int, input()))) |
소감
반응형
'◎ 자료구조와 알고리즘 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 / BOJ] 2675번 문자열 반복 (C++, Python) (0) | 2022.01.17 |
---|---|
[백준 / BOJ] 10809번 알파벳 찾기 (C++, Python) (0) | 2022.01.17 |
[백준 / BOJ] 11654번 아스키 코드 (C++, Python) (0) | 2022.01.17 |
[백준 / BOJ] 1065번 한수 (C++, Python) (0) | 2021.09.07 |
[백준 / BOJ] 4673번 셀프 넘버 (C++, Python) (0) | 2021.09.06 |
@Reo :: 코드 아카이브
자기계발 블로그