1037. 在霍格沃茨找零钱(20)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(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输出样例1:
3.2.1输入样例2:
14.1.28 10.16.27输出样例2:
-3.2.1
这里写if-else语句的时候要注意嵌套式和级联式的不同写法。
#include<stdio.h>
struct node
{
int Galleon,Sickle,Knut;
}a[2],out;
bool isBig(node a,node b)
{
if(a.Galleon > b.Galleon) return true;
else if(a.Galleon == b.Galleon)
{
if(a.Sickle > b.Sickle) return true;
else if(a.Sickle == b.Sickle)
{
if(a.Knut > b.Knut) return true;
}
}
return false;
}
void substract(node a,node b)
{
if(a.Knut >= b.Knut) out.Knut = a.Knut - b.Knut;
else
{
out.Knut = a.Knut + 29 - b.Knut;
a.Sickle--;
}
if(a.Sickle >= b.Sickle) out.Sickle = a.Sickle - b.Sickle;
else
{
out.Sickle = a.Sickle + 17 - b.Sickle;
a.Galleon--;
}
out.Galleon = a.Galleon - b.Galleon;
}
int main()
{
int i;
for(i = 0; i < 2; i++)
{
scanf("%d.%d.%d",&a[i].Galleon,&a[i].Sickle,&a[i].Knut);
}
if(isBig(a[0],a[1]))
{
printf("-");
substract(a[0],a[1]);
}
else substract(a[1],a[0]);
printf("%d.%d.%d\n",out.Galleon,out.Sickle,out.Knut);
return 0;
}