博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1058. A+B in Hogwarts (20)
阅读量:4344 次
发布时间:2019-06-07

本文共 1346 字,大约阅读时间需要 4 分钟。

题目如下:

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

设计一个结构体存储G、S、K三位,根据题目条件进位即可。

#include 
#include
using namespace std;struct GSK{ int G; int S; int K; void add(GSK other){ int carry; K += other.K; carry = K / 29; K = K % 29; S = S + carry + other.S; carry = S / 17; S = S % 17; G = G + carry + other.G; }};int main(){ GSK n1,n2; scanf("%d.%d.%d",&n1.G,&n1.S,&n1.K); scanf("%d.%d.%d",&n2.G,&n2.S,&n2.K); n1.add(n2); printf("%d.%d.%d",n1.G,n1.S,n1.K); return 0;}

转载于:https://www.cnblogs.com/aiwz/p/6154110.html

你可能感兴趣的文章
raid5什么意思?怎样做raid5?raid5 几块硬盘?
查看>>
【转】how can i build fast
查看>>
null?对象?异常?到底应该如何返回错误信息
查看>>
django登录验证码操作
查看>>
(简单)华为Nova青春 WAS-AL00的USB调试模式在哪里开启的流程
查看>>
图论知识,博客
查看>>
[原创]一篇无关技术的小日记(仅作暂存)
查看>>
20145303刘俊谦 Exp7 网络欺诈技术防范
查看>>
原生和jQuery的ajax用法
查看>>
iOS开发播放文本
查看>>
20145202马超《java》实验5
查看>>
JQuery 事件
查看>>
main(argc,argv[])
查看>>
第四阶段 15_Linux tomcat安装与配置
查看>>
NAS 创建大文件
查看>>
学习笔记-模块之xml文件处理
查看>>
接口测试用例
查看>>
Sybase IQ导出文件的几种方式
查看>>
案例:手动输入一个字符串,打散放进一个列表,小写字母反序 大写字母保持不变...
查看>>
linux 系统下 tar 的压缩与解压缩命令
查看>>