-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1251.js
More file actions
24 lines (20 loc) · 739 Bytes
/
1251.js
File metadata and controls
24 lines (20 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
최대 50개의 글자 중 쪼개는 기준점이 될 두 곳을 고르는 경우의 수
>> 2500보다 적음
>> 완전탐색 가능
*/
const INPUT_FILE = process.platform === 'linux' ? '/dev/stdin' : './input';
const word = require('fs').readFileSync(INPUT_FILE).toString().trim()
.split('');
let sol = 'z'.repeat(50);
for (let divPoint1 = 1; divPoint1 < word.length - 1; divPoint1 += 1) {
for (let divPoint2 = divPoint1 + 1; divPoint2 < word.length; divPoint2 += 1) {
const newWord = [
word.slice(0, divPoint1).reverse().join(''),
word.slice(divPoint1, divPoint2).reverse().join(''),
word.slice(divPoint2).reverse().join(''),
].join('');
if (newWord < sol) sol = newWord;
}
}
console.log(sol);