-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path14.js
More file actions
39 lines (30 loc) · 1.07 KB
/
14.js
File metadata and controls
39 lines (30 loc) · 1.07 KB
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
31
32
33
34
35
36
37
38
39
let getResult = (data) => {
let arr_EN = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
let parse_ints = str => {
return str.split(' ').filter(val => val != '').map(val => parseInt(val.trim()));
}
let [len, n] = parse_ints(data[0]);
let depricated = [];
for (let i = 1; i <= n; i++) {
let [position, depricated_letter] = data[i].split(' ').map(val => val.trim());
if (!depricated[+position]) {
depricated[+position] = new Set();
}
depricated[+position].add(depricated_letter);
}
let pass = '';
for (let i = 1; i <= len; i++) {
let allowed = arr_EN;
if (depricated[i]) {
allowed = arr_EN.filter(val => !depricated[i].has(val));
}
pass += allowed[Math.floor((allowed.length + 1) / 2) - 1];
}
return pass;
}
const { count } = require('console');
const fs = require('fs');
let fileContent = fs.readFileSync("input.txt", "utf8");
const data = fileContent.toString().trim().split("\n");
const result = getResult(data);
fs.writeFileSync("output.txt", result.toString());