PTA A+B in Hogwarts (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
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
#define PI 3.1415926
typedef long long ll;
using namespace std;
int const mod=1e9+7;
const int maxn=3e5+10;
ll S1[3],S2[3],fg[3],C[3]={10000000,17,29};
int main()
{
    scanf("%lld.%lld.%lld %lld.%lld.%lld", &S1[0], &S1[1], &S1[2], &S2[0], &S2[1], &S2[2]);
    for (ll i=2; i>=0; i--)
    {
        S1[i]+=S2[i]+fg[i];
        if (S1[i]>=C[i]&&i!=0)
        {
            fg[i-1]=S1[i]/C[i];
            S1[i]%=C[i];
        }
    }
    printf("%lld.%lld.%lld", S1[0], S1[1], S1[2]);
    return 0;
}
 

猜你喜欢

转载自blog.csdn.net/weixin_44170305/article/details/108380039