Last active
December 11, 2015 06:49
-
-
Save lambda-fairy/4562331 to your computer and use it in GitHub Desktop.
Keks solution
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
def max_index(items, start, end): | |
best_item = None | |
best_index = None | |
for index, item in zip(range(start, end), items[start:end]): | |
if best_item is None or item > best_item: | |
best_item = item | |
best_index = index | |
if best_index is None: | |
raise ValueError('maximum of empty sequence') | |
else: | |
return best_index | |
def keks(num, n_skip): | |
digits = list(num) | |
start = 0 | |
for end in range(n_skip+1, len(digits)+1): | |
start = max_index(digits, start, end) | |
yield digits[start] | |
start += 1 | |
def main(): | |
with open('keks.in', 'r') as in_f: | |
with open('keks.out', 'w') as out_f: | |
n_digits, n_skip = map(int, in_f.readline().strip().split()) | |
num = in_f.readline().strip() | |
print >>out_f, ''.join(keks(num, n_skip)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment