-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path17.js
More file actions
35 lines (31 loc) · 715 Bytes
/
17.js
File metadata and controls
35 lines (31 loc) · 715 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
25
26
27
28
29
30
31
32
33
34
35
let getResult = (data) => {
let str = data[0];
let result = 0;
let left = 0;
while (str[left] != '{' && left < str.length) {
left++;
}
let counter = 1;
for (let i = left + 1; i < str.length; i++) {
if (str[i] === '{') {
counter++;
}else if (str[i] === '}') {
counter--;
}
if (counter === 0) {
result++;
left = i + 1;
while (str[left] != '{' && left < str.length) {
left++;
}
i = left;
}
}
return result;
}
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());