1058. A+B in Hogwarts (20)

时间限制
50 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

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

思路
加法,注意进位就好。 注:
1.这道题看着很简单,然而用cin输入的是两个字符串,还得将字符串分割处理,然后转换成int,有点坑。
2.直接用scanf("%d.%d.%d",&x,&y,&z)读数据就不用处理字符串 =_=!。 代码
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
vector<int> A(),B();
string a,b;
while(cin >> a >> b)
{
int index = ;
//handle A
for(int i = ,j = ;i <a.size();i++)
{
string tmp;
if(a[i] == '.')
{
tmp = a.substr(j,i - j);
j = i + ;
A[index++] = stoi(tmp);
} if(index == )
{
tmp = a.substr(j,a.size() - j);
A[index++] = stoi(tmp);
}
}
//Handle B
index = ; for(int i = ,j = ;i <b.size();i++)
{
string tmp;
if(b[i] == '.')
{
tmp = b.substr(j,i - j);
j = i + ;
B[index++] = stoi(tmp);
}
if(index == )
{
tmp = b.substr(j,b.size() - j);
B[index++] = stoi(tmp);
}
} int add = ,sum = ;
sum = (A[] + B[]);
add = sum / ;
A[] = sum % ;
sum = A[] + B[] + add;
add = sum/;
A[] = sum % ;
A[] = A[] + B[] + add;
cout << A[] << "." <<A[] << "." << A[];
}
}

PAT1058:A+B in Hogwarts的更多相关文章

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

  2. PAT1058. A+B in Hogwarts (20)

    #include <iostream> using namespace std; int ag,as,ak; int bg,bs,bk; int cg,cs,ck; int main(){ ...

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

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

  5. A1058 A+B in Hogwarts (20)(20 分)

    A1058 A+B in Hogwarts (20)(20 分) If you are a fan of Harry Potter, you would know the world of magic ...

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

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

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

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

随机推荐

  1. 客户端状态的存储空间——Session

    http协议在设计之初被设计成无状态特性,客户端的每次请求在服务端看来都是独立且无任何相关性,同一个客户端第一次请求不会与第二次请求有任何关联,即使相隔时间很短.无状态的特性让请求变得很快速且服务器也 ...

  2. Android系统之Broadcom GPS 移植

    1.      内核部分的移植: 内核部分的移植基本上就是对芯片上下电,建立数据结构体,打通GPS通信的串口通道,以及建立文件设备结点供上层调用.所建立的文件结点是针对Power_enable和Res ...

  3. PS 图像调整算法——阈值

    PS里面这个算法,先将图像转成灰度图像,然后根据给定的阈值,大于该阈值的像素赋值为1,小于该阈值的赋值为0. if x>T, x=1; if x<T, x=0; 原图: 效果图:阈值为 1 ...

  4. wince6.0 编译报错:"error C2220: warning treated as error - no 'object' file generated"的解决办法

    内容提要:wince6.0编译报错:"error C2220: warning treated as error - no 'object' file generated" 原因是 ...

  5. 初探linux子系统集之led子系统(一)

    就像学编程第一个范例helloworld一样,学嵌入式,单片机.fpga之类的第一个范例就是点亮一盏灯.对于庞大的linux系统,当然可以编写一个字符设备驱动来实现我们需要的led灯,也可以直接利用g ...

  6. React Native Android开发环境配置

    近些年,Web前端甚是火爆,火爆程度堪比我毕业时的移动端开发一般.随着JavaScript的火爆,移动端也不安分了起来,ReactNative就异军突起了,几乎要做到"一次学习,四处开发&q ...

  7. 排序算法入门之堆排序(Java实现)

    堆排序 在学习了二叉堆(优先队列)以后,我们来看看堆排序.堆排序总的运行时间为O(NlonN). 堆的概念 堆是以数组作为存储结构. 可以看出,它们满足以下规律: 设当前元素在数组中以R[i]表示,那 ...

  8. SQL解决数值间隔问题

    有表格存放每个顾客拥有的票.现在想查看哪些顾客的票不是连号,即有间隔.并找出间隔的开始与结束数字. create table tickets ( buyer_name char(5) not null ...

  9. 使用Cli构建Go的命令行应用

    转载出处:http://www.opscoder.info/cli.html   在Go里面应用中flag这一标准库,提供了很多我们在写命令行时需要的interface,然而如果你需要更强大更好的结构 ...

  10. python函数与装饰器

    一.名字空间与作用域 1.名字空间 名字空间:赋值语句创建了约束,用来存储约束的dict被称为名字空间      赋值语句的行为:1.分别在堆和栈中创建obj与name                 ...