Created
October 25, 2022 03:39
-
-
Save 6LYTH3/eb043a6a9bf81a23303887a9af130b53 to your computer and use it in GitHub Desktop.
Dimond Problem
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
def main(): | |
# Input # | |
# first input: number of layer | |
input_layers = int(input()) | |
input_shapes = [] | |
for i in range(input_layers): | |
shape = str(input()) | |
# skip duplicate | |
if shape.upper() in input_shapes: | |
continue | |
# charactor: accept ABCDE | |
input_shapes.append(shape.upper()) | |
# End input # | |
# descending sort | |
for i in range(len(input_shapes)): | |
for j in range(i + 1, len(input_shapes)): | |
if input_shapes[i] > input_shapes[j]: | |
temp = input_shapes[i] | |
input_shapes[i] = input_shapes[j] | |
input_shapes[j] = temp | |
input_size = len(input_shapes) - 1 | |
# up side | |
# range [1,2,3,4,5] | |
for i in range(len(input_shapes)): | |
chr_index = 0 | |
for j in range(len(input_shapes)): | |
if (input_size - i) > j: | |
print(' ', end='') | |
else: | |
print(input_shapes[chr_index], end='') | |
chr_index += 1 | |
# reversed [5,4,3,2,1] | |
chr_index -= 1 | |
for j in reversed(range(len(input_shapes))): | |
if j < i: | |
chr_index -= 1 | |
if chr_index < 0: | |
break # finish | |
print(input_shapes[chr_index], end='') | |
print() # new line | |
# down side | |
for i in reversed(range(len(input_shapes) - 1)): | |
chr_index = 0 | |
for j in reversed(range(len(input_shapes))): | |
if i < j: | |
print(' ', end='') | |
else: | |
print(input_shapes[chr_index], end='') | |
chr_index += 1 | |
# reversed [5,4,3,2,1] | |
chr_index -= 1 | |
for j in reversed(range(len(input_shapes))): | |
if j < i: | |
chr_index -= 1 | |
if chr_index < 0: | |
break # finish | |
print(input_shapes[chr_index], end='') | |
print() # new line | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment