1058 A+B in Hogwarts
2024-09-06 08:49:54
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 }
最新文章
- Array&;String总结
- 数据结构:C_链表队列的实现
- dom节点的操作
- Android 坐标系和 MotionEvent 分析、滑动
- Java如何将html转以后的字符转化成正常显示的字符
- C#中 StringBuilder类 与 String类的区别---(转)
- bzoj 1188 [HNOI2007]分裂游戏(SG函数,博弈)
- Github上最受关注的前端大牛,快来膜拜吧!
- zoj 3792 Romantic Value
- mysql 假设存在id则设数据自添加1 ,不存在则加入。java月份计算比較
- ListView下拉刷新及上拉更多两种状态
- Design Patterns笔记
- pycharm的list中copy的应用
- 【洛谷P1198】最大数
- bzoj千题计划321:bzoj5251: [2018多省省队联测]劈配(网络流 + 二分)
- 转:slf4j-api、slf4j-log4j12、log4j之间关系
- 经济学人使用Golang构建微服务历程回顾
- mysql数据导入导出与数据表优化
- Android使用Custom debug keystore
- linux apache下虚拟主机配置方法
热门文章
- 顶级c程序员之路 基础篇 - 第一章 关键字的深度理解 number-1
- MVCC多版本并发控制器
- CSS:CSS基础
- 基于 react + electron 开发及结合爬虫的应用实践&#127877;
- MySQL数据库插入数据出现 ERROR 1526 (HY000): Table has no partition for value xxx
- .NET并发编程-反应式编程
- STM32 ADC详细篇(基于HAL库)
- python 操作符** (两个乘号就是乘方)
- 卷积神经网络学习笔记——轻量化网络MobileNet系列(V1,V2,V3)
- kmp&;字典树 模板