본문 바로가기

JAVA-BAEKJOON/4단계 1차원 배열

[백준/04-05] 10810 공 넣기

NO.10810 

 

풀이코드

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int arr[] = new int[N];
		int M = sc.nextInt();
		
		for(int i=0; i<M; i++) {
			int I = sc.nextInt();
			int J = sc.nextInt();
			int K = sc.nextInt();
			
			for(int j=I-1; j<J; j++) {	// index 0부터 시작이라 I-1
				arr[j] = K;
			}
		}
		for(int k=0; k<arr.length; k++) {
			System.out.print(arr[k]+" ");
		}
    }
}