题目描述
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)).
翻译:如果你是一个哈利波特的粉丝,你应该知道这个世界的魔法有它自己通用的系统—就像海格解释给哈利的哪样,“17个银Sickles 对应一个Galleon,29个Knuts对应一个Sickle,这很简单。 ”你的任务是写一个程序去计算A+B,A和B是给定的”Galleon.Sickle.Knut”形式, (Galleon是 [0, 10^7]的一个整数, Sickle是[0, 17)的整数, and Knut 是 [0, 29)的整数).
INPUT FORMAT
Each input file contains one test case which occupies a line with A and B in the standard form, separated by one space.
翻译:每个输入文件包含一组测试数据,包括一行标准格式的A和B,中间用空格隔开。
OUTPUT FORMAT
For each test case you should output the sum of A and B in one line, with the same format as the input.
翻译:对于每组输入数据,你需要用与输入格式相同的格式输出一行A+B之和。
Sample Input:
3.2.1 10.16.27
Sample Output:
14.1.28
解题思路
这道题很水,就是如果超过对应限制,上一位就+1,相当于3位数,每一位都有自己的进制。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#define INF 99999999
using namespace std;
int a[3],b[3],c[3];
int main(){
scanf("%d.%d.%d%d.%d.%d",&a[0],&a[1],&a[2],&b[0],&b[1],&b[2]);
c[2]=a[2]+b[2];if(c[2]>=29)c[1]++,c[2]%=29;
c[1]+=a[1]+b[1];if(c[1]>=17)c[0]++,c[1]%=17;
c[0]+=a[0]+b[0];
printf("%d.%d.%d\n",c[0],c[1],c[2]);
return 0;
}