반응형
Notice
Recent Posts
Recent Comments
Link
불로구
백준 2231(JAVA) - 분해합 본문
반응형
package 브루트포스;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class 분해합 {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
int result = solution(N);
bw.write(result + "\n");
bw.flush();
bw.close();
}
static int solution(int N) {
int originalNum = N;
int result = 0;
while(N > 0) {
N--;
int tmpNum = N;
int modNum = N;
while(modNum > 0) {
tmpNum += modNum % 10;
modNum /= 10;
}
if(tmpNum == originalNum) {
result = N;
}
}
return result;
}
}
반응형
'코딩테스트 > 백준' 카테고리의 다른 글
백준 7568 (JAVA) - 덩치 (0) | 2021.03.06 |
---|---|
백준 2798 (JAVA) - 블랙잭 (0) | 2021.03.06 |
[백준 - 10816 ] - 숫자카드2( JAVA ) (0) | 2021.02.11 |
[백준 - 1920 ] - 수찾기 ( JAVA ) (0) | 2021.02.11 |
Comments