PAT乙级1037. 在霍格沃茨找零钱(C语言)

AC

PAT乙级真题答案目录


#include 

int main() {
	long long Galleon, Sickle, Knut, P, A, change; //转换过程中可能超过int范围
	scanf("%lld.%lld.%lld", &Galleon, &Sickle, &Knut);
	P = (Galleon * 17 + Sickle) * 29 + Knut; //价钱 
	scanf("%lld.%lld.%lld", &Galleon, &Sickle, &Knut);
	A = (Galleon * 17 + Sickle) * 29 + Knut; //实付 
	change = A - P; 
	if(change < 0) {//钱不够 
		printf("-");
		change = -change;
	}
	printf("%d.%d.%d\n", change / 29 / 17, change / 29 % 17, change % 29);
	return 0;
}

你可能感兴趣的:(PAT乙级真题)