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 Specification:

Each input file contains one test case. Each case contains a pair of integers a and b where −106≤a,b≤106. The numbers are separated by a space.

Output Specification:

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

就是计算a+b然后输出的水题,要注意符号判断,如果为0的话就输出一个0就可以了.

做任何题都要小心结果会不会就是一个0,还有一个0不算是前导0.

#include <iostream>
#include <bits/stdc++.h>
#define de(x) cout<<#x<<" "<<(x)<<endl
using namespace std; int a[10];
int cur=0;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int sum=n+m;
bool sign_flag=true;
bool zero_flag=false;
if(sum==0)zero_flag=true;
if(sum<0)sign_flag=false,sum=-sum;///
while(sum>0)
{
a[cur++]=sum%10;
sum/=10;
}
if(!sign_flag)printf("-");
int cnt=0;
for(int i=cur-1;i>=0;i--)
{
printf("%d",a[i]);
cnt++;
if(i%3==0&&i!=0)
{
printf(",");
}
}
if(zero_flag)printf("0");
printf("\n"); return 0;
}

PAT-1001 A+B Format (20 分) 注意零的特例的更多相关文章

  1. PAT 1001 A+B Format (20分) to_string()

    题目 Calculate a+b and output the sum in standard format -- that is, the digits must be separated into ...

  2. PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642 题目描述: Calculate a+b and output the sum i ...

  3. PAT Advanced 1001 A+B Format (20 分)

    Calculate a+b and output the sum in standard format -- that is, the digits must be separated into gr ...

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

    Calculate a+b and output the sum in standard format – that is, the digits must be separated into gro ...

  5. 【PAT甲级】1001 A+B Format (20 分)

    题意:给两个整数a,b,计算a+b的值并每三位用逗号隔开输出(−1e6​​≤a,b≤1e6​​) AAAAAccepted code: #include<bits/stdc++.h> us ...

  6. PAT A1001 A+B Format (20 分)

    AC代码 #include <cstdio> #include <algorithm> using namespace std; const int maxn = 11; in ...

  7. PAT 1001 A+B Format (20 point(s))

    题目: 我一开始的思路是: 用math.h中的log10函数来计算位数(不建议这么做,因为会很慢,而且会出一点别的问题): 用pow函数根据要插入分号的位置来拆分a+b成一个个数字(例如res / p ...

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

    1001 A+B Format (20)(20 分) Calculate a + b and output the sum in standard format -- that is, the dig ...

  9. PAT 甲级1001 A+B Format (20)(C++ -思路)

    1001 A+B Format (20)(20 分) Calculate a + b and output the sum in standard format -- that is, the dig ...

随机推荐

  1. Get Argument Values From Linq Expression

    Get Argument Values From Linq Expression If you even find yourself unpacking an expression in C#, yo ...

  2. flume 诞生背景 数据同步

    flume一开始是cloudlera的项目 当时他们的工程师需要一次次地为客户编写工具 来实现数据的自动化导入

  3. Java四方面组成要素

    Java由四方面组成: Java编程语言.Java类文件格式.Java虚拟机和Java应用程序接口(Java API).它们的关系如下图所示:

  4. List根据多个字段分组

    List<ClassEntity> distinctClass = classEntities.stream().collect(Collectors.collectingAndThen( ...

  5. EXCEL生成SQL脚本

    有如下一张数据库表: 当然,Excel也是这个样子的,然后需要通过Excel的命令实现如下的脚本: insert into student(name,age) values('张三',15); 实现的 ...

  6. selenium chromedriver与chrome版本对应表

    chromedriver版本   支持的Chrome版本 v2.41               v67-69 v2.40               v66-68 v2.39             ...

  7. easyui-datagrid配置宽度高度自适应

    在style属性中,去除之前添加的width和height属性(如果有的话),然后添加"fit:false"即可.

  8. vim学习一

    来源 实验楼(shiyanlou.com)的<Vim编辑器>课程的学习报告. 6种基本模式 普通模式 默认进入vi时的模式,使用编辑器命令,i h j k l 等等 插入模式 用户按下 i ...

  9. 人工神经网络反向传播算法(BP算法)证明推导

    为了搞明白这个没少在网上搜,但是结果不尽人意,最后找到了一篇很好很详细的证明过程,摘抄整理为 latex 如下. (原文:https://blog.csdn.net/weixin_41718085/a ...

  10. 项目中easyui-tooltip提示消息运用

    easyui datagrid tooltip 对数据增加: {field:'roomCode',title:'房间名称',width:100 ,formatter: function (value, ...