C++:: 프로그래머스 < 하샤드 수 >

jahlee·2023년 7월 31일
0

프로그래머스_Lv.1

목록 보기
51/75
post-thumbnail

문제에서 요구하는 조건에 맞춰 풀면 되는 간단한 문제이다.

#include <string>
#include <vector>

using namespace std;

bool solution(int x) {
    string s = to_string(x);
    int sum = 0;
    for (auto c : s) sum += c - '0';// 각 자릿수 합
    if (x % sum) return false;// 나눠서 나머지가 나오면
    return true;
}

0개의 댓글