공 넣기 (10810)
Created:
i번 바구니부터 j번 바구니까지 k번 공을 넣어라.
Bash
Bash 1
2
3
4
5
6
7
8
9
10
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[@]}"
Node.js
JavaScript 1
2
3
4
5
6
7
8
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(" ") );
Python3
Python 1
2
3
4
5
6
7
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) )
Ruby
Ruby 1
2
3
4
5
6
7
8
9
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(" ")