PAT甲级1058答案(使用C语言)

题目描述

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

题目要求总结

题目按格式输入两个数,每个数有三位,中间以’.'隔开,从右往左,第一位数是按29进位,第二位数是按17进位,第三位数则在1-10^7之间,不考虑进位,题目比较简单

#include

int main(){
	int a1, a2, a3, b1, b2, b3;
	scanf("%d.%d.%d %d.%d.%d", &a1, &a2, &a3, &b1, &b2, &b3);
	int first = (a3 + b3) % 29;
	int c = (a3 + b3) / 29;
	int second = (a2 + b2 + c) % 17;
	c = (a2 + b2 + c) / 17;
	int third = a1 + b1 + c;
	printf("%d.%d.%d\n", third, second, first);
	return 0;
}

你可能感兴趣的:(PAT,Advance,level)