A1058 A+B in Hogwarts

题目要求

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  where  and  are given in the standard form of Galleon.Sickle.Knut (Galleon is an integer in [], 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  and  in the standard form, separated by one space.

Output Specification:

For each test case you should output the sum of  and  in one line, with the same format as the input.

Sample Input:

3.2.1 10.16.27
 

Sample Output:

14.1.28

代码

#include<cstdio>
int main() {
	const int sickle = 29;
	const int galleon = 17 * 29;
	long long num1, g1, s1, k1;
	long long num2, g2, s2, k2;
	scanf("%lld.%lld.%lld", &g1, &s1, &k1);
	scanf("%lld.%lld.%lld", &g2, &s2, &k2);
	num1 = g1 * galleon + s1 * sickle + k1;
	num2 = g2 * galleon + s2 * sickle + k2;
	long long  sum = num1 + num2;
	int a = sum / galleon;
	int b = (sum % galleon) / sickle;
	int c = (sum % galleon) % sickle;
	printf("%d.%d.%d",a,b,c);
}

注意点

中间计算过程可能溢出,需要使用long long 存储

long long num1, g1, s1, k1;
long long num2, g2, s2, k2;

 

posted @ 2022-02-05 21:07  第厘  阅读(13)  评论(0编辑  收藏  举报