PAT甲级1001. A+B Format

Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).

Input

Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.

Output

For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.

Sample Input
-1000000 9
Sample Output
-999,991
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include <queue>
#include <stack>
using namespace std;
//ios::sync_with_stdio(false);
//typedef long long ll;
const int MAXN = 100005;
//const int inf = 0x3f3f3f3f;


int main()
{
    int a,b;
    cin>>a>>b;
    int sum=a+b;
    int s;
    if(sum<0)
        s=-sum;
    else
        s=sum;
    stack<int> x;
    int t=0,h=0;
    if(sum<=999&&sum>=-999)
    {
        cout<<sum<<endl;
        return 0;
    }
    while(s!=0)
    {
        x.push(s%10);
        s/=10;
        h++;//记录数字个数
    }
    if(sum<0)
        cout<<"-";
    int flag=0;//判断剩余数字个数是否为3的倍数
    while(!x.empty())
    {
        if(h%3==0)
            flag=1;
        if(h%3!=0&&flag==0)
        {
            h--;
        }
        if(t==3&&flag==1)
        {
            cout<<",";
            t=0;
        }
        cout<<x.top();
        x.pop();
        if(flag==0&&h%3==0)
                cout<<",";
        if(flag==1)
        t++;
    }
    cout<<endl;

    return 0;
}

 
从TL431光耦到集成隔离器:3种反激电源反馈方案全对比,你的项目到底该选哪个? 本文深入对比了反激电源设计中TL431光耦、集成隔离器和原边反馈三种主流反馈方案的优缺点,帮助开发者在电源设计中选择最适合的方案。从精度、成本、隔离等级等多维度分析,为反激式(Flyback)拓扑的应用提供实用选型指南。 阅读详情

相关推荐

新手必看!无人机定高PID调参避坑指南:从理论到实战的完整流程

本文为无人机新手提供定高PID调参的完整指南,从传感器融合到抗风策略,详细解析多传感器融合、PID控制参数调试及环境干扰应对。通过实战案例和代码示例,帮助开发者快速掌握无人机定高技术,避免常见调参陷阱,提升飞行稳定性。

spark7igniter的博客 221

a+b format 涉及到的知识点

说明 以下程序为复习知识点时使用 ,没有真正的通过pat的提交。简单了解一下知识点即可 A+B Format (20)-PAT甲级真题 Calculate a + b and output the sum in standard format — that is, the digits must be separated into groups of three by commas (un...

DlnuRicardo的博客 860

Hierarchical Flow Partition(Top-down&&Bottom-up)

hierarchy flow是将设计切分成多个block,分别处理单个block,然后完成后,将它们进行拼接以完成最终的chip。一般划分为三个阶段:chip planning;physical budget就是pin assignmenthierarchy flow实现的方法有两种,一种是top-down,另一种是bottom-up,无论是哪种,都是都要通过flatten的方法分别全局范围进行优化实现。

qq_39493558的博客 3069

PAT-Java-1001-A+B Format (20)

1001. A+B Format (20) 题目阐述 Calculate a + b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than four digits).

rebornyp的博客 423

Innovus 安装全过程

【代码】Innovus 安装全过程。

lmyynlbcy的博客 5536

手把手教你绕过网易易盾验证码:滑块、点选、语序全攻略

本文深度解析了以网易易盾为代表的现代验证码技术,重点探讨了滑块、点选、语序及空间推理等交互式验证码的工作原理与对抗策略。文章从行为验证和空间推理的核心逻辑出发,剖析了验证码交互的数据流与关键参数,并提供了模拟人类行为轨迹、维护设备指纹等工程实践方法,旨在帮助开发者在合规前提下设计更健壮的自动化流程。

3c4x5z6v7b的博客 704

PAT甲级 1001. A+B Format (20) 题目翻译与答案

1001.A+B的标准格式 计算a+b,然后以标准格式输出。标准格式是指数字必须被分成三个一组,用逗号分隔(除非少于4个数字)。

Coding home - 漂流瓶jz 2240

MPU6050 vs BMX055 vs ICM20602:如何为你的项目选择最佳陀螺仪(附实测数据对比)

本文深度对比了MPU6050、BMX055和ICM20602三款主流六轴IMU传感器的核心性能。通过实测数据,分析了它们在精度、噪声、温漂、接口速度及资源占用上的差异,并提供了从项目需求出发的选型指南,帮助开发者根据预算、精度要求和处理器性能选择最合适的陀螺仪与加速度计组合。

h0i1j2k3l的博客 969

浙江大学PAT上机题解析之1001. A+B Format (20)

1001. A+B Format (20) 时间限制  400 ms 内存限制  32000 kB 代码长度限制  16000 B 判题程序    Standard 作者    CHEN, Yue Calculate a + b and output the sum in standard format -

liygcheng's coding world - 1934

【MFiX后处理】MFiX中使用des_usr_var输出颗粒的传热量(2020-11-27更新变更输出变量名方法)

参考之前Yin的那一篇博客 https://www.cnblogs.com/Jay-CFD/p/10621274.html 输出一下颗粒传热量 使用的算例是fluid_bed_dem_2d 打开des scalar tracking 前面都和Yin那篇一样,打开enable user scalar tracking 输入2 因为第一个用来测试Y加速度了 第二个输出传热量 然后在output vtk中勾选好 更改源代码 源代码为des_thermo_newvalues.f 在mfix-GUI自带的ed

beidou111的博客 1532

【DRAM存储器五十四】LPDDR5介绍--PHY简介和LPDDR5训练流程

简述LPDDR5 PHY的基本功能和训练流程简介

highman110的博客 907

PAT甲级1001_A+B Format _模拟

#include <bits/stdc++.h> using namespace std; typedef long long ll; const int inf = ~0u >> 2; //1073741823 const ll INF = ~0ull >> 2; //4611686018427387903 const int maxn = 1e3 + 10; int main() { //Solution s = Solution(); int a, b; s

HDUCheater的博客 362

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

PAT 甲级 1001  A+B Format

1001 A+B Format (20 point(s)) Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits). In...

漫浸天空的雨色的备忘录~ 4583

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

PAT 甲级题目讲解:1001《A+B Format》

本文是 PAT 甲级 1001《A+B Format》的详细题解。题目要求将两个整数之和按标准格式输出,即从右向左每三位添加一个千位分隔逗号。文章从题意拆解、样例分析入手,逐步讲解符号处理、数位拆分、字符串拼接与翻转等核心步骤,并给出完整 C++ 参考代码。此外还总结了常见错误提醒、复杂度分析以及思维拓展方向,帮助读者彻底掌握整数格式化输出的套路。

qq_35624947的博客 509

PAT甲级(1001:A+B Format)

题目要求两数之和,并按照英文输出习惯,每3位添加一个分隔符,即千位分隔符。这里只放核心判断逻辑。

elegant and beauty 445

PAT 甲级 1001 A+B Format

PAT 甲级 1001 A+B Format #include<bits/stdc++.h> using namespace std; int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int a, b; cin >> a >> b; string ans = to_string(abs(a + b)); if (a + b < 0) cout &lt

桂圆儿的仓库 86

PAT 1001 A+B Format (20分)(转化字符串)第三次重刷PAT甲级题

7月底就要考试了,四月份就立下雄心壮志要刷上甲级题5遍,如今到现在也才准备刚开始第三遍,丢人呐,最近也在刷力扣,那么就两个一起刷吧,希望七月底能有一个好成绩 不过现在PAT在线上考试了,不知道这次的含金量会降低不, 1001 A+B Format (20分) Calculate a+b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (un

stackempty2的博客 184

PAT 1001 A+B Format (20 分) ——甲级

#include<iostream> #include<string> using namespace std; int main(){ int a, b, c; scanf("%d %d", &a, &b); c = a + b; if(c < 0){ c = -1 * c; printf("-"); } string str1...

RickLin_的博客 155

pat 甲级 1001 A+B Format

这题做了一个小时主要卡在题意理解错误,第二写代码时考虑不到位。蓝色部分字体我理解成了分成三组,而题目意思是,每三个数字分成一组。后面卡到测试点2和8了 是因为我在第一个if里输出了strSum[0],没有考虑到后面对else内容的影响。

suntingsheng123的专栏 296

PAT甲级考试题库1001 A+B Format 代码实现及相关知识学习

准备参加九年九月份的PAT甲级证书考试,对网站上的题目进行总结分析: 1001题 A+B Format (20 分) Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless th...

dieshi8689的博客 329

Pat甲级 1001 A+B Format

Pat甲级 1001 A+B Format思路代码 题目网址 https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 思路 a+b按照一定格式输出,都不是大数,直接加就完事儿了,注意下0+0的情况就好.我的代码是为了练习vector容器特意写成这样的,更简单的思路应该是把相加的数字转为string,然后判断输出逗号. 代码 #include <iostream> #include <cmat

ax816的博客 231

PAT甲级 1001 A+B Format 总结

时隔两个月后,重新开始练习pat。这一次本来打算先刷一下算法笔记这本书上的习题,巩固一下基础。但是鉴于目前王道数据结构已经复习到了第六章,很多数据结构的难度算法题也算是自己用笔写过,应该不需要再从头开始写简单的题了。于是今天开始刷PAT甲级题库了。一边刷题一边翻书回顾知识点反而会更有效。今天刷的这道题是pat甲级的编号1001的题目,求的是一个a+b的运算结果。 Calculatea+ban...

ayuanzzy的博客 369

PAT甲级1001 A+B Format

PAT甲级1001 A+B Format 题目 题目链接 生词 comma n.逗号;停顿 题目大意 按要求输出a+b的结果,输出格式:每三个数就要加个逗号 题中的坑(可能不算坑但我踩了):是从后往前加逗号!!也就是说9999的正确输出应该是9,999而不是999,9 思路1: 参考柳婼大神的题解柳婼大神博客 把a+b的和转为字符串s~除了第⼀位是负号的情况,只要当前位的下标i满⾜(i + 1) % 3 == len %3并且i不是最后⼀位,就在逐位输出的时候在该位输出后的后⾯加上⼀个逗号 代码 #inc

牛呆呆同学的博客 297

PAT甲级刷题 -- 1001 A+B Format

1001 问题: A+B Foramt Question: Calculate a+b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than four digits). Input...

GuoningningPro的博客 282

PAT甲级 1001 A+B Format

PAT甲级 1001 A+B Format Calculate a+b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than four digits). Input Specifi...

flyfuture1的博客 185
上一篇: POJ3278 Catch the cow BFS广搜
下一篇: POJ1426 Find The Multiple题意及题解
Yolo_Fs
博客等级 码龄9年 41粉丝 46原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值