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. 微信小程序 scroll-view 填满剩余可用高度

    根据微信小程序 scroll-view 文档所述,scroll-view必须给定一个固定高度.那么如果我们想要让它自动填充剩余高度,该怎么办呢? 前言 在说出我的解决方案之前,先来看一下我的页面设计, ...

  2. VIM快速掌握

    vi/vim 基本使用方法 vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何最新的文本编辑器,这里只是简单地介绍一下它的用法和一小部分指令.由于对Unix及Linux系统的 ...

  3. JavaScript中三个等号和两个等号的区别(“===”与“==”的区别)

    1.===:三个等号我们称为等同符,当等号两边的值为相同类型的时候,直接比较等号两边的值,值相同则返回true,若等号两边的值类型不同时直接返回false. 例:100===“100”   //返回f ...

  4. C语言练习,可以解析协议,主机,路径,询问,片段等

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> ...

  5. 对Mysql数据表本身进行操作

    创建实验环境 mysql> create database test_db; Query OK, 1 row affected (0.00 sec) mysql> use test_db; ...

  6. 123457123456---com.threeObj3.BabyShizi02--- 宝宝识字02

    com.threeObj3.BabyShizi02--- 宝宝识字02

  7. videojs改变音量大小

    <audio id=example-video preload="auto" class="video-js vjs-default-skin" type ...

  8. Spring Cloud(6.2):搭建OAuth2 Client

    配置web.xml 添加spring-cloud-starter-security,spring-security-oauth2-autoconfigure和spring-boot-starter-o ...

  9. iOS-OC的MRC和ARC内存管理机制

    1. Objective-c语言中的MRC(MannulReference Counting) 在MRC的内存管理模式下,对变量的管理相关的方法有:retain,release和autorelease ...

  10. 01.轮播图之二 :tableView 轮播

    在做这个tablevew轮播的时候,重要的就是修改frame 和view 的翻转了:::: 也是不难的,概要的设计和scroll 轮播是一致的: 首先是 .h 的文件 @interface Table ...