알고리즘
[알고리즘] c++ cpp 하샤드 수
keel_im
2020. 10. 21. 11:17
반응형
포인트
1. 각 자릿수의 값을 어떻게 더하는가? 본인은 주로 string 을 사용한다. 자릿구 10을 활용한 방법도 있다.
🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다.
#include <string>
#include <iostream>
using namespace std;
bool solution(int x) {
string s = to_string(x);
int a = 0;
for(auto ele: s){
a+=ele - '0';
}
if(x%a==0) return true;
else return false;
}
반응형