A+B in Hogwarts
来源:互联网 发布:大数据 统计区别 编辑:程序博客网 时间:2024/05/17 03:14
题目描述
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, 107], Sickle is an integer in [0, 17), and Knut is an integer in [0, 29)).
输入描述:
Each input file contains one test case which occupies a line with A and B in the standard form, separated by one space.
输出描述:
For each test case you should output the sum of A and B in one line, with the same format as the input.
输入例子:
3.2.1 10.16.27
输出例子:
14.1.28
代码:
#include"iostream"
#include "string"
#include "cmath"
#include "vector"
#include<iomanip>
using namespace std;
struct Standard
{
int Galleon = 0;
int Sickle = 0;
int Knut = 0;
};
int main()
{
string firstNum, secondNum;
cin >> firstNum >> secondNum;
int i = 0;
Standard first, second;
int key = 0;
for(int i = 0;i < firstNum.size(); i++)
{
if (firstNum[i] == '.')
{
key++;
continue;
}
switch (key)
{
case 0:
first.Galleon = 10 * first.Galleon + (firstNum[i] - '0');
break;
case 1:
first.Sickle = 10 * first.Sickle + (firstNum[i] - '0');
break;
case 2:
first.Knut = 10 * first.Knut + (firstNum[i] - '0');
default:
break;
}
}
key = 0;
for (int i = 0; i < secondNum.size(); i++)
{
if (secondNum[i] == '.')
{
key++;
continue;
}
switch (key)
{
case 0:
second.Galleon = 10 * second.Galleon + (secondNum[i] - '0');
break;
case 1:
second.Sickle = 10 * second.Sickle + (secondNum[i] - '0');
break;
case 2:
second.Knut = 10 * second.Knut + (secondNum[i] - '0');
default:
break;
}
}
Standard result;
result.Knut = first.Knut + second.Knut;
result.Sickle = first.Sickle + second.Sickle;
result.Galleon = first.Galleon + second.Galleon;
if (result.Knut >= 29)
{
result.Knut -= 29;
result.Sickle++;
}
if (result.Sickle >= 17)
{
result.Sickle -= 17;
result.Galleon++;
}
printf("%d.%d.%d", result.Galleon, result.Sickle, result.Knut);
}
- A+B in Hogwarts
- A+B in Hogwarts
- A+B in Hogwarts
- 1058. A+B in Hogwarts
- 1058. A+B in Hogwarts
- 1058.A+B in Hogwarts
- pat1058 A+B in Hogwarts
- 1058. A+B in Hogwarts
- 1058. A+B in Hogwarts
- 1058 A+B in Hogwarts
- 1058. A+B in Hogwarts
- PAT_1058. A+B in Hogwarts
- PAT-A 1058. A+B in Hogwarts
- 1058. A+B in Hogwarts (20)- PAT
- 【PAT】1058. A+B in Hogwarts (20)
- 1058. A+B in Hogwarts (20)
- 1058. A+B in Hogwarts (20)
- 1058. A+B in Hogwarts (20)
- PAT_A 1029. Median (25)
- 支持点击放大缩小图片,拖动放大缩小图片功能
- java 环境安装
- Windows下Subversion的安装及配置
- Runnable、Callable、Future接口区别
- A+B in Hogwarts
- Java继承之间类的加载顺序, 以及代码块、构造块的执行顺序
- Linux系统简介以及为何常用于服务器
- Mybatis小结之详解Mapper.xml
- 蓝桥杯三羊献瑞全排列
- 深究JavaScript——原型
- 删除单链表中某个元素
- 面向接口编程详解(一)——思想基础
- 九度 oj 题目1549:货币问题