i번 바구니부터 j번 바구니까지 k번 공을 넣어라.
Bash
bash
read n m
arr=()
for ((i=0; i<n; i++)); do arr+=(0); done
for ((idx=0; idx<m; idx++)); do
read i j k
for ((jdx=i-1; jdx<j; jdx++)); do
arr[$jdx]=$k
done
done
echo "${arr[@]}"
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Node.js
javascript
const [[n, m], ...input] = require("fs").readFileSync(0).toString().trim().split("\n").map(x => x.split(" ").map(Number));
let arr = Array(n).fill(0);
for (let [i, j, k] of input) {
for (let idx=i-1; idx<j; idx++) {
arr[idx] = k;
}
}
console.log( arr.join(" ") );
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
Python3
python
n, m = map(int, input().split())
arr = ["0" for i in range(n)]
for idx in range(m):
i, j, k = map(int, input().split())
for jdx in range(i-1, j):
arr[jdx] = str(k)
print( ' '.join(arr) )
1
2
3
4
5
6
7
2
3
4
5
6
7
Ruby
ruby
n, m = gets.chomp.split().map {|i| i.to_i}
arr = Array.new(n, 0)
for idx in 0...m
i, j, k = gets.chomp.split().map {|i| i.to_i}
for jdx in i-1...j
arr[jdx] = k
end
end
puts arr.join(" ")
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
Comments
Not supported comment edit and upvote
You can do it on this page if you want.