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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 1058 A+B in Hogwarts (20)

    #include <stdio.h> int main() { ]; ]; ],&ans1[],&ans1[],&ans2[],&ans2[],&a ...

  8. PAT (Advanced Level) 1058. A+B in Hogwarts (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  9. PAT甲题题解-1058. A+B in Hogwarts (20)-大水题

    无语,这种水题还出,浪费时间,但又不得不A... #include <iostream> #include <cstdio> #include <algorithm> ...

  10. 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 ...

随机推荐

  1. KnowRbao_uni-app

    uni-app开发项目模板 主要的代码如下: pages.json 这里是添加页面的路径代码还可以设置标题: { "pages" : [ //pages数组中第一项表示应用启动页, ...

  2. Win32API使用技巧 -- 置顶应用

    Win32提供了SetForegroundWindow方法可以将应用设置到前台并激活,但是在某些场景下,只调用该接口会返回0,即设置失败.比如如下场景: 当前前台应用为一个全屏的应用,非前台应用的进程 ...

  3. kali 下的邮件发送工具 swaks

    kali 下的邮件发送工具 swaks Swaks 是一个功能强大,灵活,可编写脚本,面向事务的 SMTP 测试工具,目前 Swaks 托管在私有 svn 存储库中. 官方项目 http://jetm ...

  4. HDOJ-1540(线段树+较复杂的单点修改和区间查询)

    Tunnel Warfare HDOJ-1540 这题关于线段树的操作有一定的难度,需要较好的思维能力. 关于题目的详细解答已经在代码中体现了. #include<iostream> #i ...

  5. three.js cannon.js物理引擎之齿轮动画

    郭先生今天继续说一说cannon.js物理引擎,并用之前已经学习过的知识实现一个小动画,知识点包括ConvexPolyhedron多边形.Shape几何体.Body刚体.HingeConstraint ...

  6. SVHN数据集 Format1 剪裁版

    SVHN数据集官网:http://ufldl.stanford.edu/housenumbers/ SVHN数据集官方提供的有两种格式 Format1是那种在街上拍的照片,每张照片的尺寸都不同,然后l ...

  7. Educational Codeforces Round 98 (Rated for Div. 2)

    A 如果\(n = m\),答案为\(2 \times n\):如果\(n \ne m\),答案为\(2 \times max(n,m) - 1\) #include <bits/stdc++. ...

  8. mongodb 聚合(Map-Reduce)

    介绍 Map-reduce 是一种数据处理范式,用于将大量数据压缩为有用的聚合结果.对于 map-reduce 操作,MongoDB 提供MapReduce数据库命令. MongoDB中的MapRed ...

  9. 深入理解Java并发框架AQS系列(二):AQS框架简介及锁概念

    深入理解Java并发框架AQS系列(一):线程 深入理解Java并发框架AQS系列(二):AQS框架简介及锁概念 一.AQS框架简介 AQS诞生于Jdk1.5,在当时低效且功能单一的synchroni ...

  10. POJ_2828 Buy Tickets 【线段树】

    一.题目 Buy Tickets 二.分析 首先可以明确的是每个人的位置都是定的,那么如果从输入数据从后往前看,最后面的人进来的时候,他前面的人数肯定是定的. 那么可以考虑,当从后往前推时,这个人插入 ...