Created
April 4, 2020 08:43
-
-
Save theabbie/906af374873869c5b255721175242b51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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