Skip to content

Instantly share code, notes, and snippets.

@theabbie
Created April 4, 2020 08:43
Show Gist options
  • Save theabbie/906af374873869c5b255721175242b51 to your computer and use it in GitHub Desktop.
Save theabbie/906af374873869c5b255721175242b51 to your computer and use it in GitHub Desktop.
var input = `4
123411
112111
4
220`;
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}`);
}
}
processData(input);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment