[HackerRank][Python3] Separate the Numbers
2018. 9. 4. 22:53 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/separate-the-numbers/problem
My Solution :
#!/usr/bin/env python3 def is_valid(s, length): num_str = s[:length] num = int(num_str) i = 0 while i < len(s): for c in num_str: if i == len(s) or c != s[i]: return False i += 1 num += 1 num_str = str(num) return True def separate_numbers(s): for length in range(1, len(s)//2 + 1): if is_valid(s, length): return '{} {}'.format('YES', s[:length]) return 'NO' q = int(input()) for _ in range(q): s = input() result = separate_numbers(s) print(result)
'프로그래밍 > HackerRank' 카테고리의 다른 글
[HackerRank][Python3] Jumping on the Clouds (0) | 2018.09.06 |
---|---|
[HackerRank][Python3] Sequence Equation (0) | 2018.09.05 |
[HackerRank][Python3] String Construction (0) | 2018.09.05 |
[HackerRank][Python3] Beautiful Binary String (0) | 2018.09.05 |
[HackerRank][Python3] Weighted Uniform Strings (0) | 2018.09.04 |
[HackerRank][Python3] HackerRank in a String! (0) | 2018.09.03 |
[HackerRank][Python3] Truck Tour (0) | 2018.09.03 |
[HackerRank][Python3] Waiter (0) | 2018.09.03 |
최근에 달린 댓글 최근에 달린 댓글