PAT B1037 在霍格沃兹找零钱
Posted ischenjy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT B1037 在霍格沃兹找零钱相关的知识,希望对你有一定的参考价值。
AC代码
#include <cstdio>
#include <algorithm>
using namespace std;
char flag = 0; //判断付钱数是否大于价格
struct Money
int Galleon, Sickle, Knut;
price, pay, temp, sub;
void init()
price.Galleon = pay.Galleon = temp.Galleon = 0;
price.Sickle = pay.Sickle = temp.Sickle = 0;
price.Knut = pay.Knut = temp.Knut = 0;
void Sub(Money a, Money b) //a为付钱, b为价格
if(a.Knut >= b.Knut)
temp.Knut = a.Knut - b.Knut;
else if(a.Knut < b.Knut)
a.Sickle -= 1;
temp.Knut = a.Knut + 29 - b.Knut;
//printf("a.Sickle = %d c.Knut = %d\n", a.Sickle, c.Knut);
//printf("before_____a.Galleon = %d\n", a.Galleon);
if(a.Sickle >= b.Sickle)
temp.Sickle = a.Sickle - b.Sickle;
else if(a.Sickle < b.Sickle)
a.Galleon -= 1;
temp.Sickle = a.Sickle + 17 - b.Sickle;
//printf("after_____a.Galleon = %d\n", a.Galleon);
temp.Galleon = a.Galleon - b.Galleon;
int main()
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
init();
scanf("%d.%d.%d %d.%d.%d", &price.Galleon, &price.Sickle, &price.Knut, &pay.Galleon, &pay.Sickle, &pay.Knut);
// printf("price:%d.%d.%d pay:%d.%d.%d\n", price.Galleon, price.Sickle, price.Knut, pay.Galleon, pay.Sickle, pay.Knut);
if(pay.Galleon < price.Galleon)
swap(price, pay);
flag = 1;
// printf("flag:%c\n", flag);
// printf("price:%d.%d.%d pay:%d.%d.%d\n", price.Galleon, price.Sickle, price.Knut, pay.Galleon, pay.Sickle, pay.Knut);
Sub(pay, price);
if(flag == 1) printf("-");
printf("%d.%d.%d", temp.Galleon, temp.Sickle, temp.Knut);
return 0;
以上是关于PAT B1037 在霍格沃兹找零钱的主要内容,如果未能解决你的问题,请参考以下文章