PAT 1058. A+B in Hogwarts (20)
来源:互联网 发布:足彩数据分析app软件 编辑:程序博客网 时间:2024/05/21 08:43
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.27Sample Output:
14.1.28思路:按进数位取余,保存进位到下位运算。#include <cstdio>int main(){int a[3], b[3];scanf("%d.%d.%d", &a[0], &a[1], &a[2]);scanf("%d.%d.%d", &b[0], &b[1], &b[2]);int t1, t2; //保存进位t1 = (a[2] + b[2]) / 29; //按范围操作即可,进位除,结果余a[2] = (a[2]+b[2]) % 29;t2 = (a[1] + b[1] + t1) / 17;a[1] = (a[1]+b[1] + t1) % 17;a[0] = (a[0]+b[0] + t2);printf("%d.%d.%d\n", a[0], a[1], a[2]); return 0;}
- 1058. A+B in Hogwarts (20)- PAT
- 【PAT】1058. A+B in Hogwarts (20)
- PAT 1058. A+B in Hogwarts (20)
- PAT 1058. A+B in Hogwarts (20)
- pat 1058. A+B in Hogwarts (20)
- PAT 1058. A+B in Hogwarts (20)
- PAT 1058. A+B in Hogwarts (20)
- PAT---1058. A+B in Hogwarts (20)
- PAT-A 1058. A+B in Hogwarts
- PAT A 1058. A+B in Hogwarts (20)
- PAT(A) - 1058. A+B in Hogwarts (20)
- PAT-A 1058. A+B in Hogwarts (20)
- PAT-A-1058. A+B in Hogwarts (20)
- PAT 1058. A+B in Hogwarts
- 【PAT】1058. A+B in Hogwarts
- PAT-A+B in Hogwarts (20)
- PAT 1018A+B in Hogwarts (20)
- 【PAT】A1058. A+B in Hogwarts (20)
- 使用 CSS3 Flexible Boxes 布局
- Java中acm包的使用
- C++对象大小讨论
- Cognos函数(二十一) - periodsToDate
- 状态压缩二 (hiho 1048)
- PAT 1058. A+B in Hogwarts (20)
- Unity3D脚本的执行先后顺序问题
- 浅谈java的多态机制
- Supplemental log
- UIScrollView滚动, 中间显示整图, 前后露出部分图
- js中 给json对象添加新的属性
- Python实例应用
- Xcode6编译SDWebImage报错解决方法(SDWebImageDownloaderOperation.m错误)
- PAT 1040. Longest Symmetric String (25)