-
Notifications
You must be signed in to change notification settings - Fork 0
/
substring_equality.js
52 lines (42 loc) · 1.32 KB
/
substring_equality.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
46
47
48
49
50
51
52
// Max time used: 1.30/5.00, max memory used: 51216384/536870912.
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
terminal: false
});
rl.once('line', (line) => {
const text = line.toString();
rl.once('line', (line) => {
const n = parseInt(line, 10);
const lines = [];
rl.on('line', (line) => {
const signleLineWithNumbers = line.toString().split(' ').map(Number);
if (lines.length < n) {
lines.push(signleLineWithNumbers);
}
if (lines.length === n) {
const result = substringEquality({ text, n, lines }).join('\n');
process.stdout.write(result, () => {
process.exit();
});
}
});
});
});
const substringEquality = (data) => {
const { text, n, lines } = data;
const result = [];
let answer = '';
for (let i = 0; i < n; i++) {
let sub1 = text.substring(lines[i][0], lines[i][0] + lines[i][2]);
let sub2 = text.substring(lines[i][1], lines[i][1] + lines[i][2]);
if (sub1 === sub2) {
answer = 'Yes';
} else {
answer = 'No';
}
result.push(answer);
}
return result;
};
module.exports = substringEquality;