1058 A+B in Hogwarts (20 分)
Posted mered1th
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1058 A+B in Hogwarts (20 分)相关的知识,希望对你有一定的参考价值。
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
分析:水题,注意可能溢出,用long long保险点
1 /**
2 * Copyright(c)
3 * All rights reserved.
4 * Author : Mered1th
5 * Date : 2019-02-24-01.29.25
6 * Description : A1058
7 */
8 #include<cstdio>
9 #include<cstring>
10 #include<iostream>
11 #include<cmath>
12 #include<algorithm>
13 #include<string>
14 #include<unordered_set>
15 #include<map>
16 #include<vector>
17 #include<set>
18 using namespace std;
19
20 int main(){
21 #ifdef ONLINE_JUDGE
22 #else
23 freopen("1.txt", "r", stdin);
24 #endif
25 int b,c;
26 int e,f;
27 int h=0,i=0;
28 long long a,d,g=0;
29 scanf("%lld.%d.%d %lld.%d.%d",&a,&b,&c,&d,&e,&f);
30 i=f+c;
31 if(i>=29){
32 i-=29;
33 h++;
34 }
35 h=h+b+e;
36 if(h>=17){
37 h-=17;
38 g++;
39 }
40 g=g+a+d;
41 printf("%lld.%d.%d",g,h,i);
42 return 0;
43 }
以上是关于1058 A+B in Hogwarts (20 分)的主要内容,如果未能解决你的问题,请参考以下文章