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]+" ");
}
}
}
'Algorithm > BOJ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Bronze II/JAVA] 3052 ๋๋จธ์ง (0) | 2024.10.23 |
---|---|
[Bronze II/JAVA] 10813 ๊ณต ๋ฐ๊พธ๊ธฐ (0) | 2024.10.21 |
[Bronze V/JAVA] 10951 A+B-4 (EOF) (0) | 2024.10.16 |
[Bronze IV/JAVA] 11720 ์ซ์์ ํฉ (0) | 2024.10.15 |
[Bronze IV/JAVA] 2480 ์ฃผ์ฌ์ ์ธ๊ฐ (0) | 2024.10.10 |