๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ์ธ๊ณต๋ถ€/Algorithm

[๋ฐฑ์ค€][Node.js] 5052๋ฒˆ : ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2021. 11. 2.

 

 

Algorithm

-  ๋‘ ๊ฐœ ๋ฝ‘์•„์„œ ๋”ํ•˜๊ธฐ -

 


 

๋ฌธ์ œ

์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก์ด ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, ์ด ๋ชฉ๋ก์ด ์ผ๊ด€์„ฑ์ด ์žˆ๋Š”์ง€ ์—†๋Š”์ง€๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก์ด ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๋ ค๋ฉด, ํ•œ ๋ฒˆํ˜ธ๊ฐ€ ๋‹ค๋ฅธ ๋ฒˆํ˜ธ์˜ ์ ‘๋‘์–ด์ธ ๊ฒฝ์šฐ๊ฐ€ ์—†์–ด์•ผ ํ•œ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก์ด ์•„๋ž˜์™€ ๊ฐ™์€ ๊ฒฝ์šฐ๋ฅผ ์ƒ๊ฐํ•ด๋ณด์ž

  • ๊ธด๊ธ‰์ „ํ™”: 911
  • ์ƒ๊ทผ: 97 625 999
  • ์„ ์˜: 91 12 54 26

์ด ๊ฒฝ์šฐ์— ์„ ์˜์ด์—๊ฒŒ ์ „ํ™”๋ฅผ ๊ฑธ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด ์—†๋‹ค. ์ „ํ™”๊ธฐ๋ฅผ ๋“ค๊ณ  ์„ ์˜์ด ๋ฒˆํ˜ธ์˜ ์ฒ˜์Œ ์„ธ ์ž๋ฆฌ๋ฅผ ๋ˆ„๋ฅด๋Š” ์ˆœ๊ฐ„ ๋ฐ”๋กœ ๊ธด๊ธ‰์ „ํ™”๊ฐ€ ๊ฑธ๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๋”ฐ๋ผ์„œ, ์ด ๋ชฉ๋ก์€ ์ผ๊ด€์„ฑ์ด ์—†๋Š” ๋ชฉ๋ก์ด๋‹ค. 

 

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

๋ฌธ์ œ ํ’€๊ธฐ

let fs = require("fs");
let input = fs.readFileSync("/dev/stdin")
	.toString()
	.split("\n");

let idx = 0;
let number = +input[idx++];

while (number--) {
	let num = +input[idx++];
	let arr = [...Array(num)].map(() => input[idx++]).sort();
	let len = 0;
	let result = "YES";

	for (let i = 0; i < num; i++) {
		if (arr[i].slice(0, len) === arr[i - 1]) {
			result = "NO";
			break;
		}
		len = arr[i].length;
	}
	console.log(result);
}

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€