Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def romano_para_inteiro(s):
- valores = {
- 'I': 1, 'V': 5, 'X': 10,
- 'L': 50, 'C': 100,
- 'D': 500, 'M': 1000
- }
- total = 0
- anterior = 0
- for c in reversed(s.upper()):
- atual = valores.get(c, 0)
- if atual < anterior:
- total -= atual
- else:
- total += atual
- anterior = atual
- return total
- class Monarch:
- def __init__(self,s):
- self.original=s
- l=s.split(" ")
- self.name=l[0]
- self.number=romano_para_inteiro(l[1])
- def __gt__(self,other):
- if self.name>other.name:
- return True
- if self.name<other.name:
- return False
- return self.number>other.number
- def getOriginal(m):
- return m.original
- def sortMonarchs(l):
- ret=list(map(Monarch,l))
- ret=sorted(ret)
- return list(map(getOriginal,ret))
- def main():
- l=[]
- while True:
- s=input("Enter a monarch: ")
- if not s:
- break
- l.append(s)
- res=sortMonarchs(l)
- print(res)
- if __name__=="__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement