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. RK3399 focaltech敦泰触摸屏移植调试

    CPU:RK3399 系统:Android 7.1 IC:FT5406 focaltech(敦泰)触摸屏也是比较常用的,但是相对汇顶,就比较少用 RK的源码中虽然有 focaltech 的代码,但没有 ...

  2. 如何用Deepin-wine安装运行win32的程序

    创建容器 容器就是win32程序运行的环境,可以理解为一个极小的windows,在Linux下面实际对应一个文件目录,如QQ对应的容器目录是~/.deepinwine/Deepin-QQ. 创建容器最 ...

  3. Path.Combine Method

    https://docs.microsoft.com/en-us/dotnet/api/system.io.path.combine?view=netframework-4.8#System_IO_P ...

  4. PAT 甲级 1056 Mice and Rice (25 分) (队列,读不懂题,读懂了一遍过)

    1056 Mice and Rice (25 分)   Mice and Rice is the name of a programming contest in which each program ...

  5. LeetCode_171. Excel Sheet Column Number

    171. Excel Sheet Column Number Easy Given a column title as appear in an Excel sheet, return its cor ...

  6. shell脚本安装python、pip--交互式的

    首先把pip-.tgz 安装包放在 /usr/local 下面,按照顺序先安装pip,再安装python.不要先安装或只安装python,否则很容易出错, [root@bogon ~]# cat pi ...

  7. C# 3DES加密解密,差点要了命

    最近 一个项目.net 数据采用3DES加密.下面分享一下,这里的KEY采用Base64编码,便用分发,c#的Byte范围是0-255核心是确定Mode和Padding,关于这两个的意思可以搜索3DE ...

  8. Tools - 关于Network

    Tcpdump homepage - tcpdump wiki - tcpdump Wireshark homepage - wireshark wiki - wireshark Wireshark基 ...

  9. Oracle数据同步交换

    一.为了解决数据同步汇聚,数据分发,数据转换,数据维护等需求,TreeSoft将复杂的网状的同步链路变成了星型数据链路.     TreeSoft作为中间传输载体负责连接各种数据源,为各种异构数据库之 ...

  10. Redcon:快速的Redis服务器Go实现

    Fast Redis compatible server framework for Go Redcon is a custom Redis server framework for Go that ...