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. Android实现无线调试自己的应用

    开发Android的朋友都知道,真机调试需要把手机与PC相连,然后把应用部署到真机上进行安装和调试.长长的USB线显得很麻烦,而且如果需要USB接口与其他设备连接的话显得很不方便.今天介绍一种不通过U ...

  2. 《java入门第一季》之面向对象面试题

    1:方法重写和方法重载的区别?方法重载能改变返回值类型吗? 方法重写: 在子类中,出现和父类中一模一样的方法声明的现象. 方法重载: 同一个类中,出现的方法名相同,参数列表不同的现象. 方法重载能改变 ...

  3. C++中的new/delete

    不同于C语言中的malloc/free是库函数,C++语言中的new/delete是运算符,而不是库函数. new/delete执行流程 我们经常会接触到的是new/delete operator(就 ...

  4. Linux - crontab的创建以及注意事项

    [root@www ~]# crontab [-u username] [-l|-e|-r] 选项与参数: -u :只有 root 才能进行这个任务,亦即帮其他使用者创建/移除 crontab 工作排 ...

  5. C语言之linux内核--BCD码转二进制与二进制转BCD码(笔试经典)

    在分析代码之前,我们先来了解一下,BCD码和二进制到底区别在哪? 学习过计算机原理的和数字电子技术这两门课的都会知道这两个到底是什么含义,也有的同学学过了,考过了,过了一段时间又忘记了,今天,我们通过 ...

  6. 如何设置静态IP

    首先在CMD命令行ipconfig查看临时分配的IP地址: 然后打开我的"网络"--->"本地连接"--->IPv4--->属性 电信DNS劫 ...

  7. C++语言之静态变量的运用

    #include <iostream> using namespace std ; class Banana { public: static int id ; Banana(void) ...

  8. python lock, semaphore, event实现线程同步

    lock 机制不管你是java, C#, 还是python都是常用的线程同步机制, 相比较C# 的锁机制, python的加锁显得比较简单, 直接调用threading 标准库的lock 就可以了. ...

  9. Java——面向对象

    面向对象和面向过程的区别:面向对象,强调的是对象即实体:面向过程强调的是过程,即动作. 面向对象的特点:1,将复杂的问题简单化 2,更符合人们的思考习惯 3,让曾经的在过程中的执行者,变成了指挥者. ...

  10. 使用Owin的WebApi,并分离Controllers

    1.新建空白web项目 2.添加新建项=>OWIN Startup类(此时会自动下载owin,放在Packages里) 3.在Startup中输入 public void Configurati ...