标签:
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 }
标签:
原文地址:http://www.cnblogs.com/GoFly/p/4272466.html