Etc/알고리즘
[백준] 2231
jjuni_96
2024. 6. 18. 13:40
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