반응형
https://www.acmicpc.net/problem/2231
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int answer = 0;
for(int i=1; i<N; i++) {
int result = 0;
result += i;
String st = Integer.toString(i);
for(int j=0; j<st.length(); j++)
result += (st.charAt(j)-48);
if(result == N) {
answer =i;
break;
}
}
System.out.println(answer);
}
}
반응형
'알고리즘 > 문제풀이' 카테고리의 다른 글
[SWEA] 2007. 패턴 마디의 길이 (0) | 2020.01.29 |
---|---|
[백준] 7568. 덩치 (0) | 2020.01.26 |
[백준] 2789. 블랙잭 (0) | 2020.01.26 |
[SWEA] 1210. [S/W 문제해결 기본] 2일차 - Ladder1 (0) | 2020.01.25 |
[SWEA] 5215.햄버거 다이어트 (0) | 2020.01.25 |