PAT1058: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 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的更多相关文章
- 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 ...
- 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(){ ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- SpriteBuilder中的碰撞分类(Categories)和掩码(Masks)
假如有2种对象player和触发器(trigger),当玩家进入到触发器区域时则由触发器对象通知所有注册过触发器通知的对象,然后由这些对象自行选择做一些事情,比如:阻碍player的前景,触发陷阱等等 ...
- OpenGL下多个sampler在shader中的使用
在OpenGL中,sampler2D/Cube等做为uniform可以在fragment shader中使用.结合glActiveTexture和glUniform1i,实现texture与sampl ...
- Git错误一例
Bitbucket一直不稳定,push, pull经常失效.幸好还有goagent可以用. 把git的全局配置改为走goagent代理,可以正常使用: [http] proxy = http://12 ...
- The content of elements must consist of well-formed character data or markup
java 中使用dom4j解析含有特殊字符的xml文件出现了如题的错误 这个时候需要在特殊字符外面加上 <![CDATA[ /6169220648+20671/1>7+-47390045& ...
- 采用UltraISO制作U盘启动盘
采用UltraISO制作U盘启动盘 打开UltralSO,选择"文件"--->"打开",如下图: 图1 打开WIN7操作系统的ISO文件,如下图: 图2 ...
- ASI与AFN网络请求的的比较
对比 ASI AFN 更新状态 2012年10月份,已经停止更新 持续更新中,目前已更新至3.0版 介绍 ASI的直接操作对象ASIHTTPRequest,是一个实现了了NSCopying协议的NSO ...
- Android 应用内直接跳转酷市场
不确定酷市场后期是否还会该包名或者路径,目前的7.9 版本测试通过. private void gotoCoolapkMarket() { try { Intent intent = new Inte ...
- Factor Pattern----工厂模式
一. 概念 工厂模式就是负责生成其他对象的类或方法,就是把创建对象的过程封装起来,这样随时可以产生一个新的对象,减少代码之间耦合. 二. 使用场景(原因) 工厂模式可以将对象的生产从直接new 一个对 ...
- html5中的全局属性
在html5中,新增了一个"全局属性"的概念,所谓全局属性,是指可以对任何属性都使用的属性.下面列出常用的全局属性. 1.contentEditable属性,是微软开发的,该属性主 ...
- spring boot + mybatis + druid配置实践
最近开始搭建spring boot工程,将自身实践分享出来,本文将讲述spring boot + mybatis + druid的配置方案. pom.xml需要引入mybatis 启动依赖: < ...