浙江大学 pat 题解---58
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
#include"iostream"
#include "string"
using namespace std;
struct Point
{
int a;
int b;
int c;
};
Point addto(Point s1, Point s2)
{
Point re;
re.c=0;
re.b=0;
re.a=0;
re.c=s1.c+s2.c;
if(re.c>=29)
{
re.c%=29;
re.b++;
}
re.b +=s1.b+s2.b;
if(re.b>=17)
{
re.b%=17;
re.a++;
}
re.a +=s1.a+s2.a;
return re;
}
int main()
{
char s1[15],s2[15];
Point st1;
Point st2;
Point result;
char ch;
cin>>s1;
cin>>s2;
sscanf(s1,"%d%c%d%c%d",&st1.a,&ch,&st1.b,&ch,&st1.c);
sscanf(s2,"%d%c%d%c%d",&st2.a,&ch,&st2.b,&ch,&st2.c);
result = addto(st1,st2);
cout<<result.a<<"."<<result.b<<"."<<result.c<<endl;
return 0;
}
浙江大学 pat 题解---58的更多相关文章
- 浙江大学Pat 1036 题解
1036. Boys vs Girls (25) This time you are asked to tell the difference between the lowest grade of ...
- 浙江大学 pat 1006题解
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- 浙江大学PAT上机题解析之5-05. QQ帐户的申请与登陆
实现QQ新帐户申请和老帐户登陆的简化版功能.最大挑战是:据说现在的QQ号码已经有10位数了. 输入格式说明: 输入首先给出一个正整数N(<=105),随后给出N行指令.每行指令的格式为:“命令符 ...
- 浙江大学PAT考试1069~1072(2013-11-2)
11 题目地址:http://pat.zju.edu.cn/contests/pat-a-practise 1069: 由下降序和上升序两个四位数不断相减,然后得到新数据,始终会到达一个数字终止. 递 ...
- 浙江大学PAT考试1009~1012(1010上帝是冠军。。)
哎,pat1010即使java书面,只有java书面,还增加了两个点,,.啊,智商捉佳,主要pat有些不给明确的范围.造成遐想空间.. 还是按顺序介绍.. 题目地址:http://pat.zju.ed ...
- 浙江大学PAT上机题解析之1014. 福尔摩斯的约会 (20)
1014. 福尔摩斯的约会 (20) 时间限制 50 ms 内存限制 32000 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Y ...
- 浙江大学PAT上机题解析之1015. 德才论 (25)
宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人 ...
- 浙江大学PAT上机题解析之2-11. 两个有序链表序列的合并
已知两个非降序链表序列S1与S2,设计函数构造出S1与S2的并集新非降序链表S3. 输入格式说明: 输入分2行,分别在每行给出由若干个正整数构成的非降序序列,用-1表示序列的结尾(-1不属于这个序列) ...
- 浙江大学PAT上机题解析之3-05. 求链式线性表的倒数第K项
给定一系列正整数,请设计一个尽可能高效的算法,查找倒数第K个位置上的数字. 输入格式说明: 输入首先给出一个正整数K,随后是若干正整数,最后以一个负整数表示结尾(该负数不算在序列内,不要处理). 输出 ...
随机推荐
- eclipse中svn提交过滤不需要的文件
eclipse>Preference>Team>Ignored Resource 添加 .settings .classpath .project
- spring boot maven 插件
spirng boot 需要使用专用maven插件打包,才能打包.引入如下. <build> <plugins> <plugin> ...
- C#笔记(二)变量之预定义的引用类型
1.object类型 在C#中, object类型就是最终的父类型,所有内置类型和用户定义的类型都从它派生而 来. 这样, object类型就可以用于两个目的了: 可以使用object引用绑定任何子类 ...
- emacs 使用教程
http://www.cnblogs.com/liuchaogege/p/4464211.html
- hdu 1848 Fibonacci again and again(简单sg)
Problem Description 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1)=1;F(2)=2;F(n)=F(n-1)+F(n-2 ...
- ORM了解
1.hibernate通过读取Hibernate.cfg.xml文件创建SessionFactory,并通过SessionFactory创建Session(开始使用要打开,使用结束要关闭);通过Ses ...
- html+css基础篇
2016年11月19号,计划把基础在看一下,听大神说好的东西就要多看几遍,知识是学来用的解决问题的,加油 接下来的是我在自学中的小笔记吧,每天都在保持几个小时的学习思考状态,由于要升本所以学前端的时间 ...
- 解决 maven项目问题 An error occurred while filtering resources
解决方法: Maven -> Update Project.
- php 常量定义
php常量定义及取值 常量在定义时赋值: 不能变 :不能销毁: 具有超全局作用于:常量只能储存标量数据(字符 整型 浮点 ): <?php define("hello", ...
- odoo 获取当前会计年度
odoo 获取当前会计年度 def default_fiscal_year(self): current_period = self.env['account.fiscalyear'].find() ...