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 }

最新文章

  1. Array&amp;String总结
  2. 数据结构:C_链表队列的实现
  3. dom节点的操作
  4. Android 坐标系和 MotionEvent 分析、滑动
  5. Java如何将html转以后的字符转化成正常显示的字符
  6. C#中 StringBuilder类 与 String类的区别---(转)
  7. bzoj 1188 [HNOI2007]分裂游戏(SG函数,博弈)
  8. Github上最受关注的前端大牛,快来膜拜吧!
  9. zoj 3792 Romantic Value
  10. mysql 假设存在id则设数据自添加1 ,不存在则加入。java月份计算比較
  11. ListView下拉刷新及上拉更多两种状态
  12. Design Patterns笔记
  13. pycharm的list中copy的应用
  14. 【洛谷P1198】最大数
  15. bzoj千题计划321:bzoj5251: [2018多省省队联测]劈配(网络流 + 二分)
  16. 转:slf4j-api、slf4j-log4j12、log4j之间关系
  17. 经济学人使用Golang构建微服务历程回顾
  18. mysql数据导入导出与数据表优化
  19. Android使用Custom debug keystore
  20. linux apache下虚拟主机配置方法

热门文章

  1. 顶级c程序员之路 基础篇 - 第一章 关键字的深度理解 number-1
  2. MVCC多版本并发控制器
  3. CSS:CSS基础
  4. 基于 react + electron 开发及结合爬虫的应用实践&#127877;
  5. MySQL数据库插入数据出现 ERROR 1526 (HY000): Table has no partition for value xxx
  6. .NET并发编程-反应式编程
  7. STM32 ADC详细篇(基于HAL库)
  8. python 操作符** (两个乘号就是乘方)
  9. 卷积神经网络学习笔记——轻量化网络MobileNet系列(V1,V2,V3)
  10. kmp&amp;字典树 模板