Seojoo21 2022. 1. 31. 22:32

1. 문제

https://www.acmicpc.net/problem/1065

 

1065번: 한수

어떤 양의 정수 X의 각 자리가 등차수열을 이룬다면, 그 수를 한수라고 한다. 등차수열은 연속된 두 개의 수의 차이가 일정한 수열을 말한다. N이 주어졌을 때, 1보다 크거나 같고, N보다 작거나

www.acmicpc.net

2. 내 코드

import java.io.*;

class Arithmetic_Sequence {
	
	int arithmetic_sequence(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 hund = i/100; // 백의 자릿수 
				int ten = (i/10)%10; // 십의 자릿수 
				int one = i%10; // 일의 자릿수
				
				if ((hund-ten) == (ten-one)) {
					count++;
				}
			}
		}
		
		return count;
		
	}
}

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int input = Integer.parseInt(br.readLine());
		
		Arithmetic_Sequence as = new Arithmetic_Sequence();	
		System.out.println(as.arithmetic_sequence(input));

	}

}

 

3. 다시 체크할 부분

1. 알고리즘

2. 클래스 생성 및 사용 방법 다시 숙지하기.