-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathe.js
45 lines (39 loc) · 1 KB
/
e.js
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
40
41
42
43
44
45
const readline = require("readline");
const fs = require("fs");
const path = require("path");
let currentLine = 0;
let s = null;
let n = null;
let data = [];
readline
.createInterface({
input: fs.createReadStream(path.join(__dirname, "input.txt"))
})
.on("line", line => {
if (currentLine === 0) {
s = line;
} else {
if (currentLine === 1) {
n = Number(line);
} else {
data.push(line.split(" "))
data[data.length - 1][1] = Number(data[data.length - 1][1])
}
}
currentLine++;
})
.on("close", () => solve());
function solve() {
data.sort((a,b) => a[1] - b[1]);
let ans = [];
let tmp = 0;
for (let i = 0; i < data.length; i++) {
ans.push(s.substring(tmp, data[i][1]));
ans.push(data[i][0]);
tmp = data[i][1];
}
if (tmp < s.length) {
ans.push(s.substring(tmp, s.length))
}
console.log(ans.join(''));
}