1058. A+B in Hogwarts (20)
2015-11-27 13:54
351 查看
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:
Sample Output:
14.1.28
--------------------华丽的分割线-----------------------
代码:
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
--------------------华丽的分割线-----------------------
代码:
#include<cstdio> #include<cstdlib> int inputA[3]; int inputB[3]; int output[3]; int main(void) { scanf("%d.%d.%d",inputA,inputA+1,inputA+2); scanf("%d.%d.%d",inputB,inputB+1,inputB+2); int i; for(i=0;i<3;++i) { output[i] = inputA[i] + inputB[i]; } if(output[2] > 28) { output[1] += output[2] / 29; output[2] %= 29; } if(output[1] > 16) { output[0] += output[1] / 17; output[1] %= 17; } for(i=0;i<3;++i) { printf("%d",output[i]); if(i!=2) printf("."); } system("pause"); return 0; }
相关文章推荐
- Context简单说明
- jdk历史版本查找
- 纯jascript解决手机端拍照、选图后图片被旋转问题
- 给实践者的算法学习指南
- 部署servlet
- SSH2整合学习笔记
- 数据结构和算法动态可视化
- ECshop网站搬家二三事
- Android Gallery
- double free or corruption
- 1054. The Dominant Color (20)
- 高性能MySQL读书笔记:找出谁持有锁
- 访问本机的WEB API 报400错误
- 项目管理
- 1050. String Subtraction (20)
- Android lint删除无用资源文件
- Android编码时的一些实用小技巧
- Unity shader中的法线详解
- 使用SqlSessionTemplate实现数据库的操作
- Android登录实例——计时显示“隐视密码*”