【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;
}
相关推荐
先吃饱再说18 小时前
判断回文字符串,从一行代码到双指针优化
算法
见过夏天19 小时前
C++ 基础入门完全指南
c++
黄敬峰21 小时前
深入理解算法核心:从递归思想、数组扁平化到快速排序
算法
得物技术1 天前
从狂野代码到按目标生产:得物推荐 AI Harness 的工程化实践|AICon 演讲整理
人工智能·算法·架构
AI小老六1 天前
SkillOpt 架构拆解:把 Skill 文本当参数,用执行轨迹训练 Agent
后端·算法·ai编程
胡萝卜术1 天前
从“分数打架”到“排名投票”:为什么你的ChatBI必须用RRF?
算法·设计模式·面试
Asize1 天前
初识DFS 与 BFS:递归、队列与图遍历
算法
罗西的思考2 天前
机器人 / 强化学习】HIL-SERL:人类在环驱动的具身智能进化框架
人工智能·算法·机器学习
美团技术团队2 天前
LongCat 开源 VitaBench 2.0:长期动态智能体基准新标杆
人工智能·算法