首页 > 试题广场 >

在霍格沃茨找零钱(20)

[编程题]在霍格沃茨找零钱(20)
  • 热度指数:11001 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易。”现在,给定哈利应付的价钱P和他实付的钱A,你的任务是写一个程序来计算他应该被找的零钱。

输入描述:
输入在1行中分别给出P和A,格式为“Galleon.Sickle.Knut”,其间用1个空格分隔。这里Galleon是[0, 107]]区间内的整数,Sickle是[0, 
17)区间内的整数,Knut是[0, 29)区间内的整数。


输出描述:
在一行中用与输入同样的格式输出哈利应该被找的零钱。如果他没带够钱,那么输出的应该是负数。
示例1

输入

10.16.27 14.1.28

输出

3.2.1
A, B = 17, 29
a, b = [[eval(j) for j in i.split('.')] for i in input().split()]
a, b = a[0] * A * B + a[1] * B + a[2], b[0] * A * B + b[1] * B + b[2]
c = b - a if b - a >= 0 else a - b
d = c % B
c //= B
e = c % A
c //= A
if b - a < 0: print('-', end = '')
print('.'.join((str(i) for i in (c, e, d))))

发表于 2019-08-29 18:11:50 回复(0)
P,A = input().split()
lP=P.split('.')
p=''
a=''
for i in lP:
    if len(i)<2:
        i='0'+i
    p+=i
lA=A.split('.')
for j in lA:
    if len(j)<2:
        j='0'+j
    a+=j
a=int(a)
p=int(p)
if p>a:
    
    temp=A
    A=P
    P=temp

lsP=P.split('.')
lsP=list(map(int,lsP))
lsA=A.split('.')
lsA=list(map(int,lsA))


if lsP[2]<lsA[2]:
    k=lsA[2]-lsP[2]
else:
    k=lsA[2]+29-lsP[2]
    lsA[1]=lsA[1]-1

if lsP[1]<lsA[1]:
              s=lsA[1]-lsP[1]
else:
              s=lsA[1]+17-lsP[1]
              lsA[0]=lsA[0]-1
g=lsA[0]-lsP[0]
if p>a:
    print('-{}.{}.{}'.format(g,s,k))
else:
    print('{}.{}.{}'.format(g,s,k))


发表于 2019-03-30 10:43:12 回复(0)
def TransKnut(s):
    a = [int(i) fori in s.split('.')]
    knut = (a[0] * 17+ a[1]) * 29+ a[2]
    returnknut
def TransGalleon(a):
    sickle,knut = divmod(a,29)
    gallen,sickle = divmod(sickle,17)
    returnstr(gallen)+'.'+str(sickle)+'.'+str(knut)
need,give = input().split()
needK,giveK = TransKnut(need),TransKnut(give)
ifgiveK >= needK:
    print(TransGalleon(giveK - needK))
else:
    print('-'+ TransGalleon(needK - giveK))

发表于 2019-03-08 10:32:04 回复(1)
def jisuan(a,b):
    a1,a2,a3 = map(int, a.split("."))
    b1,b2,b3 = map(int, b.split("."))
    c3 = b3 - a3
    c2 = b2 - a2
    c1 = b1 - a1 if c3<0:
        c3 = c3 + 29  c2 = c2 -1  if c2 < 0:
        c2 = c2 + 17  c1 = c1 -1  return c1,c2,c3
a,b = map(str,input().split(" "))
c1,c2,c3 = jisuan(a,b) if str(c1)[0] == "-":
    c1, c2, c3 = jisuan(b, a)
    c1 = -c1 print("%d.%d.%d"%(c1,c2,c3))
发表于 2019-02-13 16:34:49 回复(0)
try:
    while True:
        string = input().split()
        pay = list(map(int,string[0].split('.')))
        cost = list(map(int,string[1].split('.')))
        payNum = (pay[0]*17+pay[1])*29+pay[2]
        costNum = (cost[0]*17+cost[1])*29+cost[2]
        remaining = costNum-payNum
        if remaining<0:
            sign = "-"
            remaining = -remaining
        else:
            sign = ""
        result = [0,0,0]
        result[2] = remaining%29
        result[0],result[1] = divmod((remaining//29),17)
        print(sign+".".join(map(str,result)))

except Exception:
    pass
编辑于 2018-09-23 12:36:19 回复(0)
needful_payment, actual_payment = raw_input().split()
recived_knut1 = 0
needful = map(int, needful_payment.split('.'))
actual = map(int, actual_payment.split('.'))
needful_knut = needful[0] * 493 + needful[1] * 29 + needful[2]
actual_knut = actual[0] * 493 + actual[1] * 29 + actual[2]
received_knut1 = actual_knut - needful_knut
received_knut = abs(received_knut1)
receive_g = received_knut / 493
received_knut = received_knut % 493
receive_s = received_knut / 29
received_knut = received_knut % 29
if received_knut1 >= 0:
    print str(receive_g) + '.' + str(receive_s) + '.' +  str(received_knut)
else:
    print '-'+ str(receive_g) + '.' + str(receive_s) + '.' + str(received_knut)
发表于 2017-07-21 16:34:40 回复(0)
P, A = raw_input().split(' ')
P_split = P.split('.')
A_split = A.split('.')
flag = False
result = ['', '', '']
a = [2, 1, 0]
for i in range(3):
    P_split[i] = int(P_split[i])
    A_split[i] = int(A_split[i])
 
for i in range(3):
    if A_split[i] > P_split[i]:
        break
    elif A_split[i] == P_split[i]:
        continue
    elif A_split[i] < P_split[i]:
        flag = True
        break
 
if flag:
 
    for i in a:
 
        if P_split[i] < A_split[i]:
            if i == 2:
                P_split[i] += 29
            elif i == 1:
                P_split[i] += 17
            if i != 0:
                P_split[i - 1] -= 1
            result[i] = str(P_split[i] - A_split[i])
        else:
            result[i] = str(P_split[i] - A_split[i])
    print ('-'+'.'.join(result))
 
else:
 
    for i in a:
        if A_split[i] < P_split[i]:
            if i == 2:
                A_split[i] += 29
            elif i == 1:
                A_split[i] += 17
            if i != 0:
                A_split[i - 1] -= 1
            result[i] = str(A_split[i] - P_split[i])
        else:
            result[i] = str(A_split[i] - P_split[i])
    print '.'.join(result)



编辑于 2017-03-07 21:10:48 回复(0)