1058. A+B in Hogwarts

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



水题,可能唯一要注意的就是不能把所有位转换到最低位,然后对两个数相加再转换回去,因为这种方法可能会溢出。只需要从低位到高位依次相加,考虑进位即可。

#include <cstdio>
int main(void) {
int g1, s1, k1, g2, s2, k2, g3, s3, k3, t; scanf("%d.%d.%d %d.%d.%d", &g1, &s1, &k1, &g2, &s2, &k2);
k3 = (k1 + k2) % 29;
t = s1 + s2 + (k1 + k2) / 29;
s3 = t % 17;
g3 = g1 + g2 + t / 17;
printf("%d.%d.%d\n", g3, s3, k3); return 0;
}

PAT-1058 A+B in Hogwarts (进制转换)的更多相关文章

  1. PAT 甲级 1019 General Palindromic Number (进制转换,vector运用,一开始2个测试点没过)

    1019 General Palindromic Number (20 分)   A number that will be the same when it is written forwards ...

  2. PAT甲级 进制转换题_C++题解

    进制转换题 PAT (Advanced Level) Practice 进制转换题 目录 <算法笔记> 重点摘要 1015 Reversible Primes (20) 1019 Gene ...

  3. SQL Server 进制转换函数

    一.背景 前段时间群里的朋友问了一个问题:“在查询时增加一个递增序列,如:0x00000001,即每一个都是36进位(0—9,A--Z),0x0000000Z后面将是0x00000010,生成一个像下 ...

  4. [No000071]C# 进制转换(二进制、十六进制、十进制互转)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. JS中的进制转换以及作用

    js的进制转换, 分为2进制,8进制,10进制,16进制之间的相互转换, 我们直接利用 对象.toString()即可实现: //10进制转为16进制 ().toString() // =>&q ...

  6. 结合stack数据结构,实现不同进制转换的算法

    #!/usr/bin/env python # -*- coding: utf-8 -*- # learn <<Problem Solving with Algorithms and Da ...

  7. 进制转换( C++字符数组 )

    注: 较为简便的方法是用 整型(int)或浮点型(long.double 注意:该类型不一定能够准确存储数据) 来存放待转换的数值,可直接取余得到每一位数值 较为稳定的方法是用 字符数组储存待转换的数 ...

  8. JS 进制转换

    十进制转换成其他进制 objectname.toString([radix])   objectname 必选项.要得到字符串表示的对象. radix 可选项.指定将数字值转换为字符串时的进制. 例如 ...

  9. php的进制转换

    学习了php的进制转换,有很多的知识点,逻辑,也有最原始的笔算,但是我们还是习惯使用代码来实现进制的转换,进制的转换代码有如下:二进制(bin)八进制( oct)十进制( dec)十六进制( hex) ...

  10. C++ 中数串互转、进制转换的类

    /******************************************************************** created: 2014/03/16 22:56 file ...

随机推荐

  1. 【Linux常见命令】cp命令

    cp - copy files and directories 拷贝文件或目标文件夹,默认不能直接拷贝目录,通过-r参数设置递归复制目录 copy 语法: cp [OPTION]... [-T] SO ...

  2. Codeforces 1291 Round #616 (Div. 2) C. Mind Control(超级详细)

    C. Mind Control You and your n−1 friends have found an array of integers a1,a2,-,an. You have decide ...

  3. 用最基本的遍历来实现判断字符串 a 是否被包含在字符串 b 中,并返回第一次出现的位置(找不到返回 -1)

    用最基本的遍历来实现判断字符串 a 是否被包含在字符串 b 中,并返回第一次出现的位置(找不到返回 -1) 例子: a='12';b='1234567'; // 返回 0 a='47';b='1234 ...

  4. train loss与test loss结果分析/loss不下降

    train loss与test loss结果分析 train loss 不断下降,test loss不断下降,说明网络仍在学习; train loss 不断下降,test loss趋于不变,说明网络过 ...

  5. 【Spark】RDD的依赖关系和缓存相关知识点

    文章目录 RDD的依赖关系 宽依赖 窄依赖 血统 RDD缓存 概述 缓存方式 RDD的依赖关系 RDD和它依赖的父RDD的关系有两种不同的类型,即窄依赖(narrow dependency) 和宽依赖 ...

  6. PHP导出excel文件之权限字段筛选导出

    因为导出excel时要过滤掉不是自身权限内的数据,权限有专门的字段,所以导出的数据要具体考量,数据库权限字段是MMId,因为登录的时候MMId已存入SESSION,所以导出的时候只要判断是否在此SES ...

  7. 第一行Kotlin系列(一)kotlin按钮点击事件

    按钮findViewBuId <Button android:id="@+id/mButton4" android:layout_width="wrap_conte ...

  8. [hdu5416 CRB and Tree]树上路径异或和,dfs

    题意:给一棵树,每条边有一个权值,求满足u到v的路径上的异或和为s的(u,v)点对数 思路:计a到b的异或和为f(a,b),则f(a,b)=f(a,root)^f(b,root).考虑dfs,一边计算 ...

  9. [hdu5254]BFS

    题意:如果一个格子的相邻四个格子中存在两个格子被标记,且这两个格子有公共点,那么这个格子也被标记.给定初始的标记状态,求最终有多少个格子被标记了 思路: 依次对每个格子进行处理,看它能否”生成“新的被 ...

  10. netty零基础入门

    直接上代码,从最基本的接收消息规则开始 package cn.qdl; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelH ...