728x90
문제

입출력

문제 분석
작은 수부터 차례대로 해당 조건에 맞게 계산하면 될듯함!
풀이
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
// 216, 198
Scanner sc = new Scanner(System.in);
int findNum = sc.nextInt();
for (int i = 1; i < findNum; i++) {
int sums = i;
String strNum = String.valueOf(i);
for (int j = 0; j < strNum.length(); j++) {
sums += strNum.charAt(j) - '0';
}
if (sums == findNum) {
System.out.println(i);
return;
}
}
System.out.println("0");
}
}
728x90
반응형
LIST
'Etc > 알고리즘' 카테고리의 다른 글
| [백준] 1009 (0) | 2024.07.04 |
|---|---|
| [백준] 19532 (0) | 2024.06.18 |
| [백준] 2798 (0) | 2024.06.18 |
| [백준] 24262 (0) | 2024.06.11 |
| [백준] 11005 (0) | 2024.06.04 |