1058 A+B in Hogwarts
分数 20
作者 CHEN, Yue
单位 浙江大学
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,107], 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.文章来源:https://www.toymoban.com/news/detail-451135.html
Sample Input:
3.2.1 10.16.27
Sample Output:
14.1.28
文章来源地址https://www.toymoban.com/news/detail-451135.html
#include <iostream>
using namespace std;
int main()
{
int tran[] = {100000000, 17, 29};
int s[3][3];
for(int i=0; i<2; ++i)
scanf("%d.%d.%d", &s[i][0], &s[i][1], &s[i][2]);
for(int i=2, d=0; i>=0; --i)
{
d += (s[0][i] + s[1][i]);
s[2][i] = d % tran[i];
d /= tran[i];
}
printf("%d.%d.%d\n", s[2][0], s[2][1], s[2][2]);
return 0;
}
到了这里,关于PAT A1058 A+B in Hogwarts的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!