Skip to content

Instantly share code, notes, and snippets.

@Peelz
Created April 4, 2020 16:16
Show Gist options
  • Save Peelz/22a89c504ce500f410a08f752f646689 to your computer and use it in GitHub Desktop.
Save Peelz/22a89c504ce500f410a08f752f646689 to your computer and use it in GitHub Desktop.
def get_current_parentheses(current, previous, next):
before = ""
after = ""
if current == 0:
return "0"
if current == next:
pass
elif current > next:
after = ")" * (current - next)
# else:
# after = "(" * (next - current)
if current == previous:
pass
elif current > previous:
before = "(" * (current - previous)
# else:
# before = ")" * (previous - current)
return before + str(current) + after
# def get_next_parentheses(current, next)
# return before + str(current) + after
def main():
test_num = int(input())
for c in range(test_num):
s = input()
result = ""
for (i, ch) in enumerate(s):
ch_i = int(ch)
previous = int(s[i - 1]) if i != 0 else 0
next = int(s[i+1]) if i != len(s)-1 else 0
result += get_current_parentheses(ch_i,previous ,next )
# result+=str(ch)
print ("Case #%s: %s" % (c+1, result))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment