모듈러하면서 더하는 방법으로 풀었는데, 다른 사람 코드를 보니 문자열로 변환해서 푼 사람이 있었다.
참신한 방법인듯.
#include <iostream>
using namespace std;
int solution(int n)
{
int answer = 0;
string s = to_string(n);
for(auto c : s)
answer += c - '0';
return answer;
}
#include <iostream>
using namespace std;
int solution(int n)
{
int answer = 0;
while(n != 0) {
answer += n % 10;
n /= 10;
}
return answer;
}