首页 > 其他 > 详细

1058. A+B in Hogwarts (20)

时间:2015-12-06 12:51:45      阅读:162      评论: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. #pragma warning(disable:4996)
  2. #include <stdio.h>
  3. #include <iostream>
  4. using namespace std;
  5. int main(void) {
  6. int ag, as, ak;
  7. int bg, bs, bk;
  8. int cg=0, cs=0, ck=0;
  9. char a[9], b[9];
  10. scanf("%s",a);
  11. sscanf(a, "%d.%d.%d", &ag, &as, &ak);
  12. scanf("%s", b);
  13. sscanf(b, "%d.%d.%d", &bg, &bs, &bk);
  14. ck = ak + bk;
  15. if (ck >= 29) {
  16. ck -= 29;
  17. cs++;
  18. }
  19. cs += (as + bs);
  20. if (cs >= 17) {
  21. cs -= 17;
  22. cg++;
  23. }
  24. cg += (ag + bg);
  25. cout << cg << "." << cs << "." << ck;
  26. /*while (true)
  27. {
  28. }*/
  29. return 0;
  30. }





1058. A+B in Hogwarts (20)

原文:http://www.cnblogs.com/zzandliz/p/5023189.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!