#22250: 救救我


ivanyang (IvanYang)

學校 : 國立竹北高級中學
編號 : 125048
來源 : [36.230.172.182]
最後登入時間 :
2023-06-11 08:54:45
a013. 羅馬數字 -- NPSC 模擬試題 | From: [1.161.214.173] | 發表日期 : 2020-08-18 22:04

g=0

h=0

Roman=["I","V","X","L","C","D","M"]

Roman_number=["1","5","10","50","100","500","1000"]

Roman_total=[]

Roman_total_2=[]

a=[]

b=[]

I="1"

V="5"

X="10"

L="50"

C="100"

D="500"

M="1,000"

#print('''I="1"

#V="5"

#X="10"

#L="50"

#C="100"

#D="500"

#M="1,000"''')

#print("""please insert two word

#ex.M L""")

while True:

    x=input()

    if x=="#":

        break

    else:

        ipt=x.split()

        a=ipt[0]

        b=ipt[1]        

        

 

    for i in range((len(a))*(7)):

#        print("len(a)=",len(a))

        if a=="#":

            False

        if a[h] == (Roman[g]):

#            print(Roman_number[g])

            Roman_total.append(int(Roman_number[g]))

            g+=1

            if h<(len(a)-1):

#                print("h=",h)

                h+=1

                g=0

            elif (len(a)-1)==h:

                break

        else:

            g+=1        

    

    

    g=0

    h=0

    for i in range((len(b))*(7)):

#        print("len(b)",len(b))

        if b[h] == (Roman[g]):

#            print(Roman_number[g])

            Roman_total_2.append(int(Roman_number[g]))

            g+=1

            if h<(len(b)-1):

#                print("h=",h)

                h+=1

                g=0

            elif h==(len(b)-1):

                break

        else:

            g+=1

    h=0

    g=0

    sum_Roman=abs((sum(Roman_total)-sum(Roman_total_2)))

#    print(sum_Roman)

    if sum_Roman==0:

        print("ZERO")

#    else :

#        print(sum_Roman)

    Roman_total=[]

    Roman_total_2=[]

    Thousand=sum_Roman//1000

    hundred=(sum_Roman%1000)//100

    one=sum_Roman%10

    ten=(sum_Roman%1000)%100//10

#    print(Thousand,hundred,ten,one)

    if Thousand!=0:

        for  i in range(Thousand):

            print("M"*Thousand,end="")

    if hundred<5:

        print("C"*hundred,end="")

    if hundred==5:

        print("D",end="")

    if hundred>5 and hundred!=9:

        print("D","C"*(hundred-5),sep="",end="")

    if hundred==9:

        print("CM",end="")

    if ten<5:

        print("X"*ten,end="")

    if ten==5:

        print("L",end="")

    if ten>5 and ten!=9:

        print("L","X"*(ten-5),sep="",end="")

    if ten==9:

        print("XC",end="")

    if one<5:

        print("I"*one,end="")

    if one==5:

        print("V",end="")

    if one>5 and one!=9:

        print("V","I"*(one-5),sep="",end="")

    if one==9:

        print("IX",end="")

 

這些程式就是過不了

 
#22251: Re:救救我


ivanyang (IvanYang)

學校 : 國立竹北高級中學
編號 : 125048
來源 : [36.230.172.182]
最後登入時間 :
2023-06-11 08:54:45
a013. 羅馬數字 -- NPSC 模擬試題 | From: [1.161.214.173] | 發表日期 : 2020-08-18 22:34

我知道了,謝謝

 
ZeroJudge Forum