Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
716 B
2
Indexable
Never
POWER = "^"
def calculate_number(rep: str):
    result = 0
    if not rep:
        return result

    ten = 0
    temp = 0
    for word in rep[::-1]:
        if word.isnumeric():
            temp += int (word) * (10 ** ten)
            ten += 1 
        elif word == POWER:
            result = helper(result, temp)
            ten = 0
            temp = 0
    
    if temp != 0:
        result = helper(result, temp)
    return result
def helper(result, temp):
    if result != 0:
        result = temp ** result 
    else:
        result = temp
    return result

n=int(input())
s=dict()
for _ in range(n):
    key=input()
    s[key]=calculate_number(key)
    
s=sorted(s.items())
for key,val in s:
    print(key) 
Leave a Comment