https://pintia.cn/problem-sets/994805342720868352/problems/994805416519647232
1058 A+B in Hogwarts (20)(20 分)提问
If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- as Hagrid explained it to Harry, "Seventeen silver Sickles to a Galleon and twenty-nine Knuts to a Sickle, it's easy enough." Your job is to write a program to compute A+B where A and B are given in the standard form of "Galleon.Sickle.Knut" (Galleon is an integer in [0, 10^7^], Sickle is an integer in [0, 17), and Knut is an integer in [0, 29)).
Input Specification:
Each input file contains one test case which occupies a line with A and B in the standard form, separated by one space.
Output Specification:
For each test case you should output the sum of A and B in one line, with the same format as the input.
Sample Input:
3.2.1 10.16.27
Sample Output:
14.1.28
注意:
这道题不像PAT-B 1037. 在霍格沃茨找零钱(20)(20 分)
1037是做差,不会溢出,但是本题算加法的和可能会溢出,如果使用int,会一直卡在第三个测试点过不去,就总是18分。
看了某大神指出的评论,将int 改为了long long 竟然就AC了,
#include <iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const int g=17*29;
const int s=29;
int main(int argc, char** argv) {
ll a1,b1,c1,a2,b2,c2;
scanf("%lld.%lld.%lld %lld.%lld.%lld",&a1,&b1,&c1,&a2,&b2,&c2);
ll price=a1*g+b1*s+c1;
ll pay=a2*g+b2*s+c2;
ll sum=price+pay;
ll a3,b3,c3;
a3=sum/g;
b3=sum%g/s;
c3=sum%s;
printf("%lld.%lld.%lld",a3,b3,c3);
return 0;
}