코테/백준

[백준/JAVA] 10810번: 공 넣기

imname1am 2023. 3. 30. 11:01
반응형

🔺 문제

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

 

 

🔺 코드

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine()," ");

        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int[] arr = new int[n];

        for(int i = 0 ; i < m ; i++) {
            st = new StringTokenizer(br.readLine()," ");

            int from = Integer.parseInt(st.nextToken());
            int to = Integer.parseInt(st.nextToken());
            int ball = Integer.parseInt(st.nextToken());

            for(int j = from - 1 ; j < to ; j++) {
            	arr[j] = ball;		        
            }
        }

        for(int i : arr) {
        	System.out.print(i + " ");
        }
    }
}
✅ 해결 아이디어
- 배열을 생성해 입력받은 공 번호를 해당 배열의 인덱스에 넣음

반응형