Can someone code this asap? Use any language that you want.
As I can use any language, I've used Python
********************
def toDecimal(s): #method to convert roman to
decimal
ones={"I":1,"II":2,"III":3,"IV":4,"V":5,"VI":6,"VII":7,"VIII":8,"IX":9}
#list storing decimal values for 1-9
tot=0 #value in decimal
pos=0 #position variable
if(s.startswith("L")): #if roman is L i.e.,
50
tot=50
return tot #return as 50 is maximum
elif(s.startswith("XL")): #if its 40
tot=40
pos=2
elif(s.startswith("XXX")):
tot=30
pos=3
elif(s.startswith("XX")):
tot=20
pos=2
elif(s.startswith("X")):
tot=10
pos=1
if(pos>=len(s)): #if entire roman string is traversed,
return value
return tot
tot=ones[s[pos:]] + tot #else find value for remaining part
and add it
return tot
def sortRoman(names):#method to sort name and
roman
l=len(names)
nam=[] #three lists for storing name,roman, and
decimal
rom=[]
dec=[]
for i in range(l):
det=names[i].split(" ") #split input into name and
roman
nam.append(det[0])
rom.append(det[1])
dec.append(toDecimal(rom[i])) #add decimal of roman in
list
namdec=[] #new list which consists of names appended with
decimal
for i in range(l):
namdec.append(nam[i] + str(dec[i])) #appending name and
decimal
(nd,n,r,d)=list(zip(*sorted(zip(namdec,nam,rom,dec))))
#sorting all the lists according to the namedec
list
nam=list(n) #converting them to list
rom=list(r)
dec=list(d)
returnlist=[] #new list which will store
output
for i in range(l):
returnlist.append(nam[i] + " " + rom[i]) #as the lists are
sorted, just append name with roman (as in input)
return returnlist
Code screenshot for indentation help:
Driver code:
Sample execution:
In case of any doubt, drop a comment and I'll surely get back to you.
Please give a like if you're satisied with the answer. Thank you.
Can someone code this asap? Use any language that you want. 2. Ancestral Names Given a...