1058. A+B in Hogwarts
If you are a fan of HarryPotter, you would know the world of magic has its own currency system -- asHagrid explained it to Harry, "Seventeen silver Sickles to a Galleon andtwenty-nine Knuts to a Sickle, it's easy enough." Your job is to write aprogram to compute A+B where A and B are given in the standard form of"Galleon.Sickle.Knut" (Galleon is an integer in [0, 107],Sickle is an integer in [0, 17), and Knut is an integer in [0, 29)).
InputSpecification:
Each input file contains one test case which occupies aline with A and B in the standard form, separated by one space.
OutputSpecification:
For each test case you should output the sum of A and B inone line, with the same format as the input.
Sample Input:
3.2.1 10.16.27
Sample Output:
14.1.28
题意:给出两组数,按位相加,后两位分别满17,29进1,求和。
PAT水题
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
int a1, a2, a3, b1, b2, b3, c1, c2, c3;
scanf("%d.%d.%d %d.%d.%d", &a1, &a2, &a3, &b1, &b2, &b3);
int jin = 0;
if(a3 + b3 >= 29)
jin = 1;
c3 = (a3 + b3) % 29;
if(a2 + b2 + jin >= 17)
{
c2 = (a2 + b2 + jin) % 17;
jin = 1;
}
else
{
c2 = a2 + b2 + jin;
jin = 0;
}
c1 = a1 + b1 + jin;
printf("%d.%d.%d\n", c1, c2, c3);
return 0;
}