PAT A1058 A+B in Hogwarts (20)
AC代码
#include <cstdio>
struct Money {
long long Galleon, Sicklke, Knut;
}A, B, Sum;
void init() {
A.Galleon = B.Galleon = Sum.Galleon = 0;
A.Sicklke = B.Sicklke = Sum.Sicklke = 0;
A.Knut = B.Knut = Sum.Knut = 0;
}
void Add(Money a, Money b) {
if(a.Knut + b.Knut >= 29) {
Sum.Sicklke += 1;
Sum.Knut += (a.Knut + b.Knut - 29);
} else Sum.Knut += (a.Knut + b.Knut);
if(Sum.Sicklke + a.Sicklke + b.Sicklke >= 17) {
Sum.Galleon += 1;
Sum.Sicklke += (a.Sicklke + b.Sicklke - 17);
Sum.Galleon += (a.Galleon + b.Galleon);
} else {
Sum.Sicklke += (a.Sicklke + b.Sicklke);
Sum.Galleon += (a.Galleon + b.Galleon);
}
}
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
init();
scanf("%lld.%lld.%lld %lld.%lld.%lld", &A.Galleon, &A.Sicklke, &A.Knut, &B.Galleon, &B.Sicklke, &B.Knut);
Add(A, B);
printf("%lld.%lld.%lld", Sum.Galleon, Sum.Sicklke, Sum.Knut);
return 0;
}
吾生也有涯,而知也无涯。