#include <iostream> #include <string> using namespace std; int solution(int n) { int answer = 0; string num = to_string(n); for(int i = 0; i < num.size(); i++) { answer += num[i]-'0'; } return answer; } | cs |
'Programmers > Level 1' 카테고리의 다른 글
[프로그래머스 1] 정수 내림차순으로 배치하기 (C/C++) (0) | 2019.10.18 |
---|---|
[프로그래머스 1] 자연수 뒤집어 배열로 만들기 (C/C++) (0) | 2019.10.18 |
[프로그래머스 1] 이상한 문자 만들기 (C/C++) (0) | 2019.10.18 |
[프로그래머스 1] 약수의 합 (C/C++) (0) | 2019.10.18 |
[프로그래머스 1] 시저 암호 (C/C++) (0) | 2019.10.18 |