码迷,mamicode.com
首页 > 其他好文 > 详细

PAT1058. A+B in Hogwarts

时间:2015-02-04 16:24:31      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:

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

思路:注意进位的方法。
技术分享
 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 int main(int argc, char *argv[])
 5 {
 6     int a,b,c;
 7     int d,e,f;
 8     scanf("%d.%d.%d %d.%d.%d",&a,&b,&c,&d,&e,&f);
 9     int cf=0;  //赋初值 
10     f=c+f;
11     if(f>=29)
12     {
13         cf=f/29;
14         f=f-29*cf;
15     }
16     e=b+e+cf;
17     cf=0;
18     if(e>=17)
19     {
20         cf=e/17;
21         e=e-17*cf;
22     }
23     d=a+d+cf;
24     printf("%d.%d.%d\n",d,e,f);
25     return 0;
26 }
View Code

 

PAT1058. A+B in Hogwarts

标签:

原文地址:http://www.cnblogs.com/GoFly/p/4272466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!