原题
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.
Sample Input:
3.2.1 10.16.27
Sample Output:
14.1.28
大体题意
霍格沃兹的货币系统分为三种,Galleon、Sickle以及Knut
17Sickle=1Galleon,29Knut=1Sickle
要求将两部分的货币大小相加
思路
就是一个简单的进位问题,从后往前将三个部分分别相加,多的进位即可
代码
#include<iostream>
using namespace std;
int main()
{
int g1, g2, s1, s2, k1, k2;
char a, b;
cin >> g1 >> a >> s1 >> b >> k1;
cin >> g2 >> a >> s2 >> b >> k2;
//cout << g1 << " " << s1 << " " << k1 << endl;
//cout << g2 << " " << s2 << " " << k2 << endl;
int g, s, k;
int add;
k = k1 + k2;
add = k / 29;
k = k % 29;
//cout << add << " " << k << endl;
s = s1 + s2 + add;
add = s / 17;
s = s % 17;
//cout << add << " " << s << endl;
g = g1 + g2 + add;
//cout << g << endl;
cout << g << "." << s << "." << k << endl;
return 0;
}