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] Jack server installation not found

    CPU:RK3399 系统:Android 7.1 服务器上第一次编译 Android 7.1 的代码,提示 Jack server 没有安装. Jack server installation no ...

  2. 如何获取UA?

    代码: function whatBrowser() { document.Browser.Name.value = navigator.appName; document.Browser.Versi ...

  3. opencv 检测人脸、人眼

    This tutorial code’s is shown lines below. You can also download it from here . The second version ( ...

  4. java udp通信

    package net.kkxm.kms;  import java.net.DatagramPacket; import java.net.DatagramSocket; import java.n ...

  5. leetcode 62. Unique Paths 、63. Unique Paths II

    62. Unique Paths class Solution { public: int uniquePaths(int m, int n) { || n <= ) ; vector<v ...

  6. 【分类算法】K近邻(KNN) ——kd树(转载)

    K近邻(KNN)的核心算法是kd树,转载如下几个链接: [量化课堂]一只兔子帮你理解 kNN [量化课堂]kd 树算法之思路篇 [量化课堂]kd 树算法之详细篇

  7. robot用例执行常用命令(还没试)

    执行命令 执行一个用例 robot -t “testcase_name“ data_test.robot 按用例文件执行 robot data_test.robot或者robot --suite “p ...

  8. php判断进程是否存在

    //计划任务定时检测master进程是否存在,不存在则启动,以root用户运行 public function checkMaster() { $cmd = 'ps axu|grep "Uc ...

  9. Python3安装后无法使用退格键

    解决办法 # 安装readline模块 yum -y install readline-devel # 进入Python安装目录 cd /usr/python/Python-3.7.2 # 重新安装 ...

  10. charles 高级批量请求

    本文参考:charles 高级批量请求 这个我感觉有点鸡肋,真正的批量请求,推荐使用JMter charles 高级批量请求就是下面这种简单的设置的 简单的使用还是可以的; 比如简单的测试下,向某一个 ...