#include <string> #include <vector> using namespace std; bool solution(int x) { // 자릿수 합 구하기 string num = to_string(x); int digitSum = 0; for(int i = 0; i < num.size(); i++) { digitSum += num[i]-'0'; } if(x % digitSum == 0) { return true; } else { return false; } } | cs |
'Programmers > Level 1' 카테고리의 다른 글
[프로그래머스 1] 행렬의 덧셈 (C/C++) (0) | 2019.10.19 |
---|---|
[프로그래머스 1] 핸드폰 번호 가리기 (C/C++) (0) | 2019.10.19 |
[프로그래머스 1] 평균 구하기 (C/C++) (0) | 2019.10.19 |
[프로그래머스 1] 콜라츠 추측 (C/C++) (2) | 2019.10.19 |
[프로그래머스 1] 최대공약수와 최소공배수 (C/C++) (0) | 2019.10.19 |