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. RDS和ROS使用小结

    微软的RDS和linux下的ROS,都已经使用了一段时间,RDS已经很久不更新了,前景必然不如ROS,但无奈用得顺手,还是偶尔怀旧一下. 使用RDS除了内置的文档需要仔细阅读,有些corobot.pr ...

  2. StarUML添加自定义approach和profile

    来源:fasiondog 添加Approch StarUML中的Approch也就是创建项目时的模板,其中预定义了所使用方法的模型和视图.StarUML默认Approach如下: StarUML的Ap ...

  3. Linux 内核配置机制(make menuconfig、Kconfig、makefile)讲解

    前面我们介绍模块编程的时候介绍了驱动进入内核有两种方式:模块和直接编译进内核,并介绍了模块的一种编译方式--在一个独立的文件夹通过makefile配合内核源码路径完成 那么如何将驱动直接编译进内核呢? ...

  4. 03_Nginx添加新模块

     1 进入nginx安装目录,查看nginx版本及其编译参数: [root@localhost nginx]# ./nginx -V nginx version: nginx/1.8.0 buil ...

  5. 第十一章 图像之2D(1)SpriteBatch

    Android游戏开发群:290051794 Libgdx游戏开发框架交流群:261954621 作者:宋志辉  出处:http://blog.csdn.net/song19891121 本文版权归作 ...

  6. Demonstration of DB Query Analyzer 6.03 Installation and Running on Microsoft Windows 8

    Demonstration of DB Query Analyzer 6.03 Installation and Running on Microsoft Windows 8 Ma Genfeng ( ...

  7. ubuntu下搭建gtk+编程环境

    首先gtk+项目主页为: http://www.gtk.org/ gtk+现在有2和3两种版本,使用 sudo apt-get install gnome-core-devel 可以一次性安装2个版本 ...

  8. Android开发技巧——高亮的用户操作指南

    Android开发技巧--高亮的用户操作指南 2015-12-15补记: 发现使用PopupWindow进行遮罩层的显示,在华为P7上会有问题.具体表现为:画出来的高亮部分会偏下.原因为:通过view ...

  9. ZooKeeper 会话超时

    1.会话概述 在ZooKeeper中,客户端和服务端建立连接后,会话随之建立,生成一个全局唯一的会话ID(Session ID).服务器和客户端之间维持的是一个长连接,在SESSION_TIMEOUT ...

  10. HBase丢失数据的故障和原因分析

    hbase的稳定性是近期社区的重要关注点,毕竟稳定的系统才能被推广开来,这里有几次稳定性故障和大家分享.     第一次生产故障的现象及原因     现象: 1 hbase发现无法写入 2 通过hbc ...