티스토리 뷰

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

 

12354번: Ocean View (Small)

The first line of the input gives the number of test cases, T. T test cases follow. Each test case will consist of two lines. The first line will contain a single integer N, the number of houses on Awesome Boulevard. The next line will list the height of e

www.acmicpc.net

const input = require('fs')
	.readFileSync('./dev/stdin')
	.toString()
	.trim()
	.split('\n')
	.map((v) => v.split(' ').map(Number));
const [T] = input.shift();
const answer = [];
for (let t = 0; t < T; t++) {
	const [N] = input.shift();
	const house = input.shift();
	const stack = [];
	stack.push(house.shift());

	let destroy = 0;
	while (house.length > 0) {
		const h = house.shift();
		if (h > stack[stack.length - 1]) {
			stack.push(h);
		} else {
			destroy++;
			stack.pop();
			stack.push(h);
		}
	}
	answer.push(destroy);
}

console.log(answer.map((v, i) => `Case #${i + 1}: ${v}`).join('\n'));
728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함