Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const readline = require("readline");
- function solve(lines) {
- let S = lines.shift().split("").map(Number);
- S.push(0);
- let max = 0;
- const res = [];
- for (let i = 0; i < S.length; i++) {
- const mem = S[i];
- if (mem > max) {
- for (let j = 0; j < mem - max; j++) {
- res.push("(");
- }
- } else if (mem < max) {
- for (let j = 0; j < max - mem; j++) {
- res.push(")");
- }
- }
- max = mem;
- res.push(mem);
- }
- // pop 0 out
- res.pop();
- process.stdout.write(`${res.join("")}\n`);
- }
- // **** UTILS **** //
- function readRawLines() {
- return new Promise((resolve) => {
- const rl = readline.createInterface({
- input: process.stdin,
- output: process.stdout,
- terminal: false,
- });
- const rawLines = [];
- rl.on("line", function (line) {
- rawLines.push(line);
- });
- rl.on("close", () => {
- resolve(rawLines);
- });
- });
- }
- (async function main() {
- const lines = await readRawLines();
- const N = +lines.shift();
- for (let caseNo = 1; caseNo <= N; caseNo++) {
- process.stdout.write(`Case #${caseNo}: `);
- solve(lines);
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement