1058. A+B in Hogwarts (20)

时间限制
50 ms
内存限制
32000 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

#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的更多相关文章

  1. 浙江大学Pat 1036 题解

    1036. Boys vs Girls (25) This time you are asked to tell the difference between the lowest grade of ...

  2. 浙江大学 pat 1006题解

    1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  3. 浙江大学PAT上机题解析之5-05. QQ帐户的申请与登陆

    实现QQ新帐户申请和老帐户登陆的简化版功能.最大挑战是:据说现在的QQ号码已经有10位数了. 输入格式说明: 输入首先给出一个正整数N(<=105),随后给出N行指令.每行指令的格式为:“命令符 ...

  4. 浙江大学PAT考试1069~1072(2013-11-2)

    11 题目地址:http://pat.zju.edu.cn/contests/pat-a-practise 1069: 由下降序和上升序两个四位数不断相减,然后得到新数据,始终会到达一个数字终止. 递 ...

  5. 浙江大学PAT考试1009~1012(1010上帝是冠军。。)

    哎,pat1010即使java书面,只有java书面,还增加了两个点,,.啊,智商捉佳,主要pat有些不给明确的范围.造成遐想空间.. 还是按顺序介绍.. 题目地址:http://pat.zju.ed ...

  6. 浙江大学PAT上机题解析之1014. 福尔摩斯的约会 (20)

    1014. 福尔摩斯的约会 (20) 时间限制   50 ms 内存限制   32000 kB 代码长度限制   8000 B 判题程序     Standard     作者     CHEN, Y ...

  7. 浙江大学PAT上机题解析之1015. 德才论 (25)

    宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人 ...

  8. 浙江大学PAT上机题解析之2-11. 两个有序链表序列的合并

    已知两个非降序链表序列S1与S2,设计函数构造出S1与S2的并集新非降序链表S3. 输入格式说明: 输入分2行,分别在每行给出由若干个正整数构成的非降序序列,用-1表示序列的结尾(-1不属于这个序列) ...

  9. 浙江大学PAT上机题解析之3-05. 求链式线性表的倒数第K项

    给定一系列正整数,请设计一个尽可能高效的算法,查找倒数第K个位置上的数字. 输入格式说明: 输入首先给出一个正整数K,随后是若干正整数,最后以一个负整数表示结尾(该负数不算在序列内,不要处理). 输出 ...

随机推荐

  1. jQuery的入门操作

    jQuery html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,add ...

  2. mysql 查看数据库中所有表的记录数

    use information_schema; SELECT DISTINCT t.table_name, t.engine '表引擎', t.table_rowsFROM TABLES tWHERE ...

  3. 设计模式 -- 中介者设计模式 (Mediator Pattern)

    中介者模式的定义:将多对多关系分散为一对多的关系,将网状结构变成星状结构,降低复杂度,提高扩展性. 角色: Mediator :抽象中介者角色,以抽象类的方式实现,生命具体对象,以及抽象方法: Con ...

  4. C语言温度

    #include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or a ...

  5. 详细介绍Java垃圾回收机制

    垃圾收集GC(Garbage Collection)是Java语言的核心技术之一,之前我们曾专门探讨过Java 7新增的垃圾回收器G1的新特性,但在JVM的内部运行机制上看,Java的垃圾回收原理与机 ...

  6. redisTemplate keys方法 为空

    我遇到的原因是spring.xml配置有问题,应该为: <bean id="redisTemplate" class="org.springframework.da ...

  7. Leetcode 解题报告

    347. Top K Frequent Elements Given a non-empty array of integers, return the k most frequent element ...

  8. 面试题-Java基础-垃圾回收

    1.Java中垃圾回收有什么目的?什么时候进行垃圾回收? 垃圾回收的目的是识别并且丢弃应用不再使用的对象来释放和重用资源. 2.System.gc()和Runtime.gc()会做什么事情? 这两个方 ...

  9. centos php nginx 添加到service

    1. nginx A. # vi /etc/init.d/nginx B. #!/bin/sh # Comments to support chkconfig on RedHat Linux # ch ...

  10. i++与++i区别使用

    中心:使用变量自增或者处减使用尽量使用++i与--i,而不要去使用i++与i-- ++i与--i可以做左值也可以做右值,而i++与i--只能做右值. 对于基础类型i++与++i结果相同,但是i++肯定 ...