**题目概述:
如果你是哈利·波特**迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易。”
现在,给定哈利应付的价钱P和他实付的钱A,你的任务是写一个程序来计算他应该被找的零钱。
输入格式:
输入在1行中分别给出P和A,格式为“Galleon.Sickle.Knut”,其间用1个空格分隔。这里Galleon是[0, 10^7]区间内的整数,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
思路:
通过最小单位进行比较看看是给的多还是付的多
从而得出正负
之后在进行借位运算得出答案
#include<stdio.h>
int main() {
int PGalleon, PSickle, PKnut;
int AGalleon, ASickle, AKunt;
int Galleon, Sickle, Kunt;
int PAllKnut, AAllKnut;
scanf("%d.%d.%d %d.%d.%d", &PGalleon, &PSickle, &PKnut, &AGalleon, &ASickle, &AKunt);
PAllKnut = PGalleon * 17 * 29 + PKnut;
AAllKnut = AGalleon * 17 * 29 + AKunt;
if (AAllKnut > PAllKnut) {
if (AKunt >= PKnut) {
Kunt = AKunt - PKnut;
}
else{
if (ASickle != 0) {
ASickle -= 1;
AKunt += 29;
Kunt = AKunt - PKnut;
}
else {
AGalleon -= 1;
ASickle += 17;
ASickle -= 1;
AKunt += 29;
Kunt = AKunt - PKnut;
}
}
if (ASickle >= PSickle) {
Sickle = ASickle - PSickle;
}
else {
AGalleon -= 1;
ASickle += 17;
Sickle = ASickle - PSickle;
}
Galleon = AGalleon - PGalleon;
printf("%d.%d.%d", Galleon, Sickle, Kunt);
}
else if (AAllKnut == PAllKnut) {
printf("0.0.0");
}
else {
printf("-");
if (PKnut >= AKunt) {
Kunt = PKnut - AKunt;
}
else {
if (PSickle != 0) {
PSickle -= 1;
PKnut += 29;
Kunt = PKnut - AKunt;
}
else {
PGalleon -= 1;
PSickle += 17;
PSickle -= 1;
PKnut += 29;
Kunt = PKnut - AKunt;
}
}
if (PSickle >= ASickle) {
Sickle = PSickle - ASickle;
}
else {
PGalleon -= 1;
PSickle += 17;
Sickle = PSickle - ASickle;
}
Galleon = PGalleon - AGalleon;
printf("%d.%d.%d", Galleon, Sickle, Kunt);
}
return 0;
}