Skip to content

Instantly share code, notes, and snippets.

@DongguemYoo
Created May 6, 2020 02:19
Show Gist options
  • Save DongguemYoo/27eb91637f878a9ac423c92aba4058ba to your computer and use it in GitHub Desktop.
Save DongguemYoo/27eb91637f878a9ac423c92aba4058ba to your computer and use it in GitHub Desktop.
코딩테스트 연습문제 하샤드 수.cs
//와 리얼 직관적으로 바로 풀어버렷다! 2분컷?
public bool solution(int x)
{
bool answer = true;
char[] tmp = x.ToString().ToCharArray();
int hap = 0;
for (int i = 0; i < tmp.Length; i++)
{
hap += int.Parse(tmp[i].ToString());
}
if (x % hap != 0)
return false;
return answer;
}
//다른 사람이 푼 방식은 n%10을 이용해서 1의자리까지 더하는 방식으로 풀었음
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment