【PAT甲级真题】- A+B in Hogwarts

题目来源

A+B in Hogwarts - 牛客
A+B in Hogwarts - PTA

Description

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 , 10 7 0,10\^7 0,107, Sickle is an integer in [ 0 , 17 ) [0, 17) [0,17), and Knut is an integer in [ 0 , 29 ) [0, 29) [0,29)).

Input Specification:

Each input file contains one test case which occupies a line with A A A and B B B in the standard form, separated by one space.

Output Specification:

For each test case you should output the sum of A A A and B B B in one line, with the same format as the input.

Sample Input:

复制代码
3.2.1 10.16.27

Sample Output:

复制代码
14.1.28

题目大意

输入两个数 A , B A,B A,B ,它们都有三个字段组成,第一个字段的范围是 0 , 10 7 0,10\^7 0,107,第二个字段的范围是 [ 0 , 17 ) [0,17) [0,17) ,第三个字段的范围是 [ 0 , 29 ) [0,29) [0,29),计算 A + B A+B A+B ,并以同样的形式输出

思路简介

真的跟普通 A + B A+B A+B 的难度差不多,输入时分字段输入,相加判断进位即可

遇到的问题

  1. 无,一遍过

代码

cpp 复制代码
/**
 * A+B in Hogwarts (20)
 * https://www.nowcoder.com/pat/5/problem/4111
 * https://pintia.cn/problem-sets/994805342720868352/exam/problems/type/7?problemSetProblemId=994805416519647232
 */
#include<bits/stdc++.h>
using namespace std;

void solve(){
    int a1,b1,c1,a2,b2,c2;
    char c;
    cin>>a1>>c>>b1>>c>>c1>>a2>>c>>b2>>c>>c2;
    int p=0;
    int c3=c1+c2;
    if(c3>28)c3-=29,p=1;
    int b3=b1+b2+p;
    if(b3>16)b3-=17,p=1;
    else p=0;
    int a3=a1+a2+p;
    c='.';
    cout<<a3<<c<<b3<<c<<c3<<'\n';
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //fstream in("in.txt",ios::in);cin.rdbuf(in.rdbuf());
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
相关推荐
·薯条大王2 小时前
经济实惠玩云服务器|一台云服务器多人共用,子账号配置教程
java·linux·运维·服务器·汇编·c++·python
To_OC3 小时前
LC 438 找到所有字母异位词:暴力超时后,我靠滑动窗口一招搞定
javascript·算法·leetcode
Forever Nore6 小时前
学完C语言力扣第一题做不来正常吗
数据结构·算法
hansang_IR7 小时前
【题解】LC:倍增 / 区间并查集(Range Parallel Unionfind)
c++·算法·并查集
东东最爱敲键盘7 小时前
day7.c++继承
c++
沫璃染墨8 小时前
《从零入门Linux系统篇(十五):系统工具篇·六——GDB调试器详解:从程序执行控制到高级调试技巧》
linux·运维·服务器·c语言·c++
吃着火锅x唱着歌8 小时前
Effective C++ 学习笔记 条款40 明智而审慎地使用多重继承
c++·笔记·学习
Tisfy8 小时前
LeetCode 3731.找出缺失的元素:哈希 / 排序
算法·leetcode·哈希算法·排序·哈希表
醉城夜风~8 小时前
(超详细)C++ STL list容器详解:从使用方法到双向链表底层原理全面解析
c++·windows