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], 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
题意:
按照特殊的进制实现加法运算。
思路:
模拟。
Code:
1 #include <bits/stdc++.h>
2
3 using namespace std;
4
5 vector<int> praseString(string str) {
6 int pos1 = str.find('.');
7 int pos2 = str.find('.', pos1 + 1);
8 string num1, num2, num3;
9 num1 = str.substr(0, pos1);
10 num2 = str.substr(pos1 + 1, pos2 - pos1 - 1);
11 num3 = str.substr(pos2 + 1);
12 vector<int> res;
13 res.push_back(stoi(num1));
14 res.push_back(stoi(num2));
15 res.push_back(stoi(num3));
16 return res;
17 }
18
19 int main() {
20 string num1, num2;
21 cin >> num1 >> num2;
22 vector<int> v1 = praseString(num1);
23 vector<int> v2 = praseString(num2);
24 int galleon, sickle, knut, add;
25 knut = (v1[2] + v2[2]) % 29;
26 add = (v1[2] + v2[2]) / 29;
27 sickle = (v1[1] + v2[1] + add) % 17;
28 add = (v1[1] + v2[1] + add) / 17;
29 galleon = v1[0] + v2[0] + add;
30 cout << galleon << "." << sickle << "." << knut << endl;
31 return 0;
32 }
1058 A+B in Hogwarts的更多相关文章
- PAT 1058 A+B in Hogwarts
1058 A+B in Hogwarts (20 分) If you are a fan of Harry Potter, you would know the world of magic ha ...
- 1058 A+B in Hogwarts (20 分)
1058 A+B in Hogwarts (20 分) If you are a fan of Harry Potter, you would know the world of magic has ...
- pat 1058 A+B in Hogwarts(20 分)
1058 A+B in Hogwarts(20 分) If you are a fan of Harry Potter, you would know the world of magic has i ...
- PAT 甲级 1058 A+B in Hogwarts (20 分) (简单题)
1058 A+B in Hogwarts (20 分) If you are a fan of Harry Potter, you would know the world of magic ha ...
- PAT甲级——1058 A+B in Hogwarts
1058 A+B in Hogwarts If you are a fan of Harry Potter, you would know the world of magic has its own ...
- 1058 A+B in Hogwarts (20分)
1058 A+B in Hogwarts (20分) 题目: If you are a fan of Harry Potter, you would know the world of magic h ...
- 1058 A+B in Hogwarts (20)
#include <stdio.h> int main() { ]; ]; ],&ans1[],&ans1[],&ans2[],&ans2[],&a ...
- PAT (Advanced Level) 1058. A+B in Hogwarts (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT甲题题解-1058. A+B in Hogwarts (20)-大水题
无语,这种水题还出,浪费时间,但又不得不A... #include <iostream> #include <cstdio> #include <algorithm> ...
- PTA(Basic Level)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 -- a ...
随机推荐
- DRF的orm多表关系补充及serializer子序列化
目录 一.控制多表关系的字段属性 1.如何建立基表 2.断开连表关系 3.四种级联关系 二.子序列化 一.控制多表关系的字段属性 1.如何建立基表 要在基表中配置Meta,设置abstract=Tru ...
- 一个页面中多个window.onload = function(){}冲突问题解决思路
转: 一个页面中多个window.onload = function(){}冲突问题解决思路 一个页面中多个window.onload = function(){}冲突问题解决思路 参考文章: (1) ...
- 人脸识别分析小Demo
人脸识别分析 调用 腾讯AI人脸识别接口 测试应用 纯py文件测试照片 # -*- coding: utf-8 -*- import json from tencentcloud.common imp ...
- 25个关键技术点,带你熟悉Python
摘要:本文收纳了Python学习者经常使用的库和包,并介绍了Python使用中热门的问题. 01.Python 简介 什么是 Python 一种面向对象的高级动态可解释型脚本语言. Python 解释 ...
- Fastjson <=1.2.24-反序列化-任意命令执行
漏洞分析 https://www.secpulse.com/archives/72391.html 复现参考 https://www.cnblogs.com/hack404/p/11980791.ht ...
- 白嫖微软Azure12个月服务器
前言 Azure是微软提供的一个云服务平台.是全球除了AWS外最大的云服务提供商.Azure是微软除了windows之外另外一个王牌,微软错过了移动端,还好抓住了云服务.这里的Azure是Azure国 ...
- 如何报告FreeBSD 的bug?
https://bugs.freebsd.org/bugzilla/ 注册个账号即可,请使用英语,把程序在不同程序上的运行结果列出来即可- 注意标记架构,如果有log还请一并附上,英语差可以 ...
- 24端口以太网FPGA的开发板
板卡架构 板载FPGA(K7-325T)处理24端口10/100/1000M以太网数据: FPGA外挂4Gbit的DDR3颗粒,最大支持800MHz: 板载CPU进行系统配置.管理,并与客户端软件通信 ...
- Apache配置 7.静态元素过期时间
(1)介绍 那到底能缓存多久呢?如果服务器上的某个图片更改了,那么应该访问新的图片才对.这就涉及一个静态文件缓存时长的问题,也叫作"缓存过期时间".在httpd的配置文件中,我们是 ...
- 自定义校验注解ConstraintValidator
一 前言 系统执行业务逻辑之前,会对输入数据进行校验,检测数据是否有效合法的.所以我们可能会写大量的if else等判断逻辑,特别是在不同方法出现相同的数据时,校验的逻辑代码会反复出现,导致代码冗余, ...