Problem Solving/Baekjoon
[백준] 1065 한수 - Brute Force / Java
graycode
2022. 11. 21. 19:56
• 문제 링크
1065번: 한수
어떤 양의 정수 X의 각 자리가 등차수열을 이룬다면, 그 수를 한수라고 한다. 등차수열은 연속된 두 개의 수의 차이가 일정한 수열을 말한다. N이 주어졌을 때, 1보다 크거나 같고, N보다 작거나
www.acmicpc.net
• 풀이 과정
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
bw.write(String.valueOf(getCount(n)));
bw.flush();
}
private static int getCount(int n) {
int cnt = 99;
if (n < 100)
return n;
else {
for (int i = 100; i <= n; i++) {
int h = i / 100;
int t = (i / 10) % 10;
int o = i % 10;
if (t - h == o - t)
cnt++;
}
}
return cnt;
}
}