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. “蚂蚁牙黑”太火,想玩就用ModelArts做一个!

    摘要:本文将介绍如何借力一站式 AI 开发平台,"傻瓜式"操作实现生成"蚂蚁牙黑"小视频. 作者:华为云EI专家胡琦 一夜之间,朋友圈都在"蚂蚁牙黑& ...

  2. HDOJ-4725(Dijikstra算法+拆点求最短路)

    The Shortest Path in Nya Graph HDOJ-4725 这题是关于最短路的问题,但是和常规的最短路有点不同的就是这里多了层次这一结构. 为了解决这一问题可以把每一层抽象或者划 ...

  3. c# float类型和double类型相乘出现精度丢失

    c# float类型和double类型相乘出现精度丢失 double db = 4.0; double db2 = 1.3; float f = 1.3F; float f2 = 4.0F; Deci ...

  4. 翻译:《实用的Python编程》03_05_Main_module

    目录 | 上一节 (3.4 模块) | 下一节 (3.6 设计讨论) 3.5 主模块 本节介绍主程序(主模块)的概念 主函数 在许多编程语言中,存在一个主函数或者主方法的概念. // c / c++ ...

  5. 后台开发:核心技术与应用实践 -- C++

    本书介绍的"后台开发"指的是"服务端的网络程序开发",从功能上可以具体描述为:服务器收到客户端发来的请求数据,解析请求数据后处理,最后返回结果. C++编程常用 ...

  6. [virtualenv][python] 环境管理——对 virtualenv 更轻便的封装

    virtualenv_simple_wrapper 如有错误,欢迎指出 Char-z 项目地址 gitee: virtualenv_simple_wrapper 使用说明 下载文件 virtualen ...

  7. iOS 面试秘籍全套

    栏目将持续更新--请iOS的小伙伴关注!   (答案不唯一,仅供参考,文章最后有福利) iOS面试题大全(上) iOS面试题大全(下) 目录: iOS面试题:Run Loop iOS面试题:性能优化 ...

  8. hexo+github 博客绑定域名

    关于博客的搭建分为以下几步: 申请域名可以在万维网上申请一个自己的独特域名,本博客的域名即为zhengwei.xyz. 域名解析域名申请成功后继续在万维网上进行操作,进入管理自己的域名界面,在要解析的 ...

  9. linux中c语言编程main函数和参数

    linux下main函数的的标准调用函数的标准形式 int main(int char,char *argv[]) 在main函数的两个参数中,argc必须是整型变量,其是命令行的参数的数目,argv ...

  10. 【JVM进阶之路】一:Java虚拟机概览

    1.Java简史 Java语言是一门通用的.面向对象的.支持并发的程序语言.全球从事Java相关开发的人员已经数以百万计. 从1995年"Java"正式出现以来,Java已经经历了 ...