각 자리의 수만 구하면 된다.
예를들어 2356일시 2356 + 2+ 3+ 5+ 6 인 것이다.
그리고 생성자가 없을 시 출력하는 것이니 이것을 구분해줘야 하는게 팁이다.
public class b4673 {
public static void main(String[] args){
int result = 0;
int t1=0; //1의 자리
int t10=0; //10의 자리
int t100=0; //100의 자리
int t1000=0; //1000의 자리
boolean[] bArr = new boolean[10000]; //true,false로 출력을 구분
for(int i = 1; i<=10000; i ++){
if(i<100){
t1 = i % 10;
t10 = (i / 10) %10;
result = i + t1 + t10;
}else if(i<1000){
t1 = i % 10;
t10 = (i / 10) %10;
t100 = i / 100;
result = i + t1 + t10 + t100;
}else if(i<10000){
t1 = i % 10;
t10 = (i / 10) %10;
t100 = (i / 100)%10;
t1000 = i / 1000;
result = i + t1 + t10 + t100 + t1000;
}
if(result<10000) {
bArr[result] = true; //위에서 만들어진 수는 모두 true로 변경
}
}
for(int i = 1 ; i<10000; i++){
if(!bArr[i]){ //위에서 true 바꾸지 않은 생성자가 없는 친구들만 출력
System.out.println(i);
}
}
}
}
'백준 문제풀이' 카테고리의 다른 글
[백준] 9012번 (0) | 2024.04.18 |
---|---|
[백준]10773 (0) | 2024.04.15 |
[백준] 1021번 (0) | 2024.04.09 |
[백준] 10815번 (2) | 2024.04.01 |
[백준] 2775번 (0) | 2024.03.31 |