Created
May 6, 2020 02:19
-
-
Save DongguemYoo/27eb91637f878a9ac423c92aba4058ba to your computer and use it in GitHub Desktop.
코딩테스트 연습문제 하샤드 수.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//와 리얼 직관적으로 바로 풀어버렷다! 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