Skip to content

Commit 0aae319

Browse files
[BOJ] 1283 단축키 지정 (S1)
1 parent dbd9bff commit 0aae319

File tree

2 files changed

+60
-7
lines changed

2 files changed

+60
-7
lines changed

서정우/5주차/260126.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// https://www.acmicpc.net/problem/1283
2+
const fs = require("fs");
3+
const filePath = process.platform === "linux" ? "/dev/stdin" : "./서정우/input.txt";
4+
const input = fs.readFileSync(filePath).toString().trim().split("\n");
5+
6+
const N = Number(input[0]);
7+
const lines = input.slice(1);
8+
const keymap = new Map();
9+
const result = [];
10+
11+
const wrappingWithBrackets = (str, index) => {
12+
return str.slice(0, index) + "[" + str.slice(index, index + 1) + "]" + str.slice(index + 1);
13+
};
14+
15+
for (let i = 0; i < N; i++) {
16+
const word = lines[i].split(" ");
17+
let mapString = "";
18+
let isMapped = false;
19+
20+
for (let j = 0; j < word.length; j++) {
21+
const cap = word[j][0].toUpperCase();
22+
23+
if (!isMapped && !keymap.get(cap)) {
24+
keymap.set(cap, 1);
25+
isMapped = true;
26+
mapString +=
27+
j < word.length - 1
28+
? wrappingWithBrackets(word[j], 0) + " "
29+
: wrappingWithBrackets(word[j], 0);
30+
} else {
31+
mapString += j < word.length - 1 ? word[j] + " " : word[j];
32+
continue;
33+
}
34+
}
35+
36+
if (mapString.length === lines[i].length) {
37+
for (let k = 0; k < lines[i].length; k++) {
38+
if (lines[i][k] !== " " && !keymap.get(lines[i][k].toUpperCase())) {
39+
keymap.set(lines[i][k].toUpperCase(), 1);
40+
result.push(wrappingWithBrackets(lines[i], k));
41+
break;
42+
} else if (k === lines[i].length - 1) {
43+
result.push(lines[i]);
44+
}
45+
}
46+
} else {
47+
result.push(mapString);
48+
}
49+
}
50+
51+
console.log(result.join("\n"));

서정우/input.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
6
2-
0 0 0 0 0 0
3-
0 1 0 0 0 0
4-
0 0 0 0 0 0
5-
0 0 0 0 0 0
6-
0 0 0 0 0 0
7-
0 0 0 0 0 0
1+
8
2+
New window
3+
New file
4+
Copy
5+
Undo
6+
Format
7+
Font
8+
Cut
9+
Paste

0 commit comments

Comments
 (0)