Skip to content

Instantly share code, notes, and snippets.

@theabbie
Created April 4, 2020 11:14
Show Gist options
  • Save theabbie/00362cc39dd4bddaf2db6c4d4d8b0e65 to your computer and use it in GitHub Desktop.
Save theabbie/00362cc39dd4bddaf2db6c4d4d8b0e65 to your computer and use it in GitHub Desktop.
function processData(input) {
var lines = input.split("\n");
var t = parseInt(input[0]);
for (l=1; l<=t; l++) {
var str = lines[l].split("").map(m=>parseInt(m));
var ans = "";
ans += "(".repeat(str[0]);
for (i=0; i<str.length-1; i++) {
ans+=str[i];
if (str[i]>str[i+1]) {ans+=")".repeat(str[i]-str[i+1])}
if (str[i]<str[i+1]) {ans+="(".repeat(str[i+1]-str[i])}
}
ans+=str[str.length-1];
ans += ")".repeat(str[str.length-1]);
console.log(`Case #${l}: ${ans}\n`);
}
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function () {
processData(_input);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment