Last active
January 1, 2018 15:33
-
-
Save natebwangsut/99aa7fdf02da6059553a45f6e2fa1ef7 to your computer and use it in GitHub Desktop.
HackerRank: Separate the Numbers
This file contains 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
#!/bin/python3 | |
import sys | |
DEBUG = False | |
q = int(input().strip()) | |
for a0 in range(q): | |
s = input().strip() | |
if DEBUG: print(s) | |
if len(s) == 1: | |
print('NO') | |
continue | |
original_n = 1 | |
n = 1 | |
pointer = 0 | |
first_sequence = s[pointer:pointer+n] | |
while pointer+n < len(s) and n > 0: | |
num = s[pointer:pointer+n] | |
if DEBUG: print(num) | |
nextn = pointer + n | |
if num[-1] == '9': | |
n = len(str(int(num)+1)) | |
nextnum = s[nextn:nextn + n] | |
if DEBUG: print(nextnum) | |
if int(num) == int(nextnum)-1 and num[0] != '0' and nextnum[0] != '0': | |
pointer = nextn | |
if (pointer+n) >= len(s): | |
print('YES', first_sequence) | |
if DEBUG: print() | |
break | |
if DEBUG: print('-') | |
else: | |
if DEBUG: print('+') | |
original_n += 1 | |
n = original_n | |
pointer = 0 | |
first_sequence = s[pointer:pointer+n] | |
if pointer+n >= len(s): | |
print('NO') | |
if DEBUG: print('') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment