✍个人博客:https://blog.csdn.net/Newin2020?spm=1011.2415.3001.5343
📚专栏地址:PAT题解集合
📝原题地址:题目详情 - 1153 Decode Registration Card of PAT (pintia.cn)
🔑中文翻译:解码PAT准考证
📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!
❤️如果有收获的话,欢迎点赞👍收藏📁,您的支持就是我创作的最大动力💪
题目详情 - 1058 A+B in Hogwarts (pintia.cn)
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(Galleonis an integer in [0,107],Sickleis an integer in [0, 17), andKnutis 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
- 1
Sample Output:
14.1.28
- 1
这道题是要我们去模拟进制运算,给定两个数,格式是 a.b.c ,c 的范围在 [0,29) ,b 的范围在 [0,17) ,也就是说 c 每达到 29 就会往 b 进一位即二十九进制,而 b 每达到 17 就会往 a 进一位即十七进制。
现在就要我们通过这个进制要求去计算两个给定格式的数之和,并且输出最终结果。
a,b,c 输入进来,然后先将对应位相加。c 的进位情况,将 c 进的位加到 b 上,然后再处理 b 的进位情况并加到 a 上。#include
using namespace std;
int main()
{
int a1, b1, c1, a2, b2, c2;
scanf("%d.%d.%d %d.%d.%d", &a1, &b1, &c1, &a2, &b2, &c2);
a1 += a2, b1 += b2, c1 += c2;
b1 += c1 / 29, c1 %= 29;
a1 += b1 / 17, b1 %= 17;
printf("%d.%d.%d", a1, b1, c1);
return 0;
}