슈콩

[BOJ] 백준 1019 책 페이지 본문

Algorithms/Baekjoon

[BOJ] 백준 1019 책 페이지

shukong 2025. 9. 6. 12:13

[문제]

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

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Main {
	static int cnt =1;
	static int[] num;
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	int n = Integer.parseInt(br.readLine());
    	num = new int[10];
    	int start = 1;
    	int end = n;
    	while(start<=end) {
    		while(start%10!=0 && start<=end) {
    			rangeOut(start);
    			start++;
    		}
    		if(start>end) break;
    		while(end%10!=9 && start<=end) {
    			rangeOut(end);
    			end--;
    		}
    		if(start>end) break;
    		start /= 10;
    		end /= 10;
    		for(int i=0;i<10;i++) {
    			num[i] += (end-start+1) * cnt;
    		}
    		cnt *= 10;
    	}
    	for(int i=0;i<10;i++) {
    		System.out.println(num[i]);
    	}
    }
    private static void rangeOut(int v) {
    	while(v>0) {
    		num[v%10] += cnt;
    		v /= 10;
    	}
    }
}

 

'Algorithms > Baekjoon' 카테고리의 다른 글

[BOJ] 백준 1038 감소하는 수  (0) 2025.09.08
[BOJ] 백준 10250 ACM 호텔  (0) 2025.09.07
[BOJ] 백준 1011 Fly me to the Alpha Centauri  (0) 2025.09.06
[BOJ] 백준 11051 이항계수2  (0) 2025.09.05
[BOJ] 백준 6064 카잉 달력  (0) 2025.09.05