题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400
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).

Input Specification:

Each input file contains one test case. Each case contains a pair of integers a and b where −10​6​​≤a,b≤10​6​​. 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

AC代码:
 #include <iostream>
#include<cstdio>
using namespace std;
int main(int argc, char const *argv[])
{
int a, b;
cin >> a >> b; int c = a + b;
if (a + b < ) {
cout << "-";
c = -c;
}
if (c >= ) {
printf("%d,%03d,%03d\n", c / , c % / , c % ); } else if (c >= ) {
printf("%d,%03d\n", c / , c % );
} else {
printf("%d\n", c );
} return ;
}

PAT甲级 1001 A+B Format的更多相关文章

  1. 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 ...

  2. 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 ...

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

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

  4. PAT 甲级 1001 A+B Format

    https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 Calculate a + b and ou ...

  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 gro ...

  6. PAT甲 1001. A+B Format (20) 2016-09-09 22:47 25人阅读 评论(0) 收藏

    1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calculate ...

  7. 【PAT】1001. A+B Format (20)

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

  8. 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 ...

  9. PAT甲级1001水题飘过

    #include<iostream> using namespace std; int main(){ int a, b; while(scanf("%d%d", &a ...

随机推荐

  1. CentOS7攻克日记(一) —— 安装ISO

    因为工作需要,开发环境需要装在centos7上面,这对用惯了ubuntu 这种Debian系的我,此刻只想说一句MMP   自从刚开始弄到现在VM里面已经躺了一堆的Centos7的尸体了,这次从头初始 ...

  2. 【搬运工】修改mysql数据库的时区

    转载:https://blog.csdn.net/huangyuehong914/article/details/81742039 --------------------- ------------ ...

  3. C#异常重试通用类Retry

    //Retry机制 public static class Retry { /// <summary> /// 重试零个参数无返回值的方法 /// </summary> /// ...

  4. 忽略 iconv 转码错误导致输出中断

    在遇到一些特殊字符时候,使用iconv转码会提示报错,导致整段文字输出为空,解决的方法是增加TRANSLIT//IGNORE $str = iconv("UTF-8", " ...

  5. Apache和Nginx的区别

    Nginx 轻量级,采用 C 进行编写,同样的 web 服务,会占用更少的内存及资源 抗并发,nginx 以 epoll and kqueue 作为开发模型,处理请求是异步非阻塞的,负载能力比 apa ...

  6. 一键安装Lnmp教程

    LNMP一键安装包 系统需求: CentOS/RHEL/Fedora/Debian/Ubuntu/Raspbian Linux系统 需要3GB以上硬盘剩余空间 128M以上内存,Xen的需要有SWAP ...

  7. DAY18 常用模块(二)

    一.随机数:RANDOM 1.(0,1)小数:random.random() 2.[1,10]整数:random.randint(1,10) 3.[1,10)整数:random.randrang(1, ...

  8. 用Python实现支持向量机并处理Iris数据集

    SVM全称是Support Vector Machine,即支持向量机,是一种监督式学习算法.它主要应用于分类问题,通过改进代码也可以用作回归.所谓支持向量就是距离分隔面最近的向量.支持向量机就是要确 ...

  9. textarea跟随内容自动伸缩高度实现方案

    监听input事件,然后将textarea的style.height设置为最低高度(19px),进而获取到元素的scrollHeight,然后将scroolHeight设置为style.height

  10. magic