반복문으로 풀면 됨.
자릿수 덧셈은 LV 1에서 자주 보인다.
#include <string>
#include <vector>
using namespace std;
bool solution(int x) {
int sum = 0;
for (int i = x; i != 0; i /= 10)
sum += i % 10;
if (x % sum == 0)
return true;
else
return false;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV1 행렬의 덧셈 (0) | 2022.04.27 |
|---|---|
| [프로그래머스] (C++) LV1 핸드폰 번호 가리기 (0) | 2022.04.27 |
| [프로그래머스] (C++) LV1 평균 구하기 (0) | 2022.04.27 |
| [프로그래머스] (C++) LV1 콜라츠 추측 (0) | 2022.04.27 |
| [프로그래머스] (C++) LV1 최대공약수와 최소공배수 (0) | 2022.04.27 |