한수(1065)
X가 한수인지 판별하는 함수를 정의하여 문제를 해결해 봅시다
Last updated
X가 한수인지 판별하는 함수를 정의하여 문제를 해결해 봅시다
Last updated
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.println(count(num));
sc.close();
}
public static int count(int num){
int count = 0;
if(num<100){
return num;
}
else{
count = 99;
if(num == 1000){
num = 999;
}
for(int i=100; i<=num; i++){
int h = i / 100;
int t = (i/10)%10;
int o = i % 10;
if((h-t) == (t-o)){
count++;
}
}
}
return count;
}
}import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int cnt = 0;
if(n>=100){
if(n==1000)
n=999;
cnt+=99;
for(int i=100; i<=n; i++){
if(fn(i))
cnt++;
}
System.out.println(cnt);
}else{
System.out.println(n);
}
}
public static boolean fn(int n) {
int one = n % 10;
int sec = n / 10 % 10;
int thr = n / 100 % 10;
return (thr-sec) == (sec-one);
}
}