Hamutaro - Hamtaro 4

Algorithm/BOJ

[Bronze III/JAVA] 10810 ๊ณต ๋„ฃ๊ธฐ

carsumin 2024. 10. 20. 16:12

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

 

 

  • ์—ฌ๋Ÿฌ๋ฒˆ ์ฝ๊ณ  ๋ฌธ์ œ๋ฅผ ์ดํ•ดํ–ˆ๋‹ค
  • ํ•ด๊ฒฐ๋ฐฉ๋ฒ• ์ž์ฒด๋Š” ์‰ฌ์šด๋ฐ ๋ฌธ์ œ๋ฅผ ์ดํ•ดํ•˜๋Š” ๋ฐ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆผ
  • ์ด์ค‘ for๋ฌธ์„ ์‚ฌ์šฉํ•  ๋•Œ index ๋ฒ”์œ„๋ฅผ ์ฃผ์˜ํ•ด์•ผํ•จ
  • ์˜ˆ๋ฅผ ๋“ค์–ด์„œ ๋ฌธ์ œ์—์„œ ๋งํ•˜๋Š” 2๋ฒˆ ๋ฐ”๊ตฌ๋‹ˆ๋ถ€ํ„ฐ 5๋ฒˆ ๋ฐ”๊ตฌ๋‹ˆ๋Š” ๋ฐฐ์—ด๋กœ ๋”ฐ์ง€๋ฉด 1๋ฒˆ๋ถ€ํ„ฐ 4๋ฒˆ์ผ ๊ฒƒ
  • ๋”ฐ๋ผ์„œ ๋ฐ˜๋ณต๋ฌธ์„ ์‹คํ–‰ํ•  ๋•Œ -1์„ ํ•ด์•ผํ•จ

 

๋‚ด ํ’€์ด

 

import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //๋ฐ”๊ตฌ๋‹ˆ๋ฅผ N๊ฐœ ๊ฐ€์ง€๊ณ  ์žˆ์Œ
        int n = sc.nextInt();
        int[] arr = new int[n];
        //M๋ฒˆ ๊ณต์„ ๋„ฃ์Œ
        int m = sc.nextInt();
        
        for(int a=0; a<m; a++){
            //์„ธ ์ •์ˆ˜ i,j,k
            int i = sc.nextInt();
            int j = sc.nextInt();
            int k = sc.nextInt();
            for(int b=i-1; b<j; b++){ //i๋ถ€ํ„ฐj๊นŒ์ง€ k๋ฒˆ ๋ฒˆํ˜ธ ๋„ฃ์Œ
                arr[b] = k;
            }
        }
        
        for(int c=0; c<arr.length; c++){
            System.out.print(arr[c]+" ");
        }
    }
}