题目链接: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. 【搬运工】linux下创建用户(一)

    转载:http://www.cnblogs.com/ylan2009/articles/2321177.html linux下创建用户(一) Linux 系统是一个多用户多任务的分时操作系统,任何一个 ...

  2. hbase调优配置项笔记

    gc配置 hbase-env.sh export HBASE_OPTS="$HBASE_OPTS -XX:+UseConcMarkSweepGC" export HBASE_OPT ...

  3. sqlserver存储过程的使用

    参考网址:https://www.cnblogs.com/chaoa/articles/3894311.html(存储过程)    https://www.cnblogs.com/selene/p/4 ...

  4. Log4net详细说明

    1.概述 log4net是.Net下一个非常优秀的开源日志记录组件.log4net记录日志的功能非常强大.它可以将日志分不同的等级,以不同的格式,输出到不同的媒介.本文主要是介绍如何在Visual S ...

  5. java native用法

    说明: native关键字说明其修饰的方法是一个原生态方法,方法对应的实现不是在当前文件,而是在用其他语言(如C和C++)实现的文件中.Java语言本身不能对操作系统底层进行访问和操作,但是可以通过J ...

  6. 《R语言入门与实践》第六章:R 的环境系统

    前言 这一章在对象的基础之上,讲解了对象所处的环境,进一步讲了环境对对象的作用,以及如何使用环境.结构如下: 环境的定义和操作 环境的规则 制作闭包 环境 R 环境的定义 在 R 中,每一个数据对象都 ...

  7. vue-cli卸载旧版,再重新安装后还显示的是旧的版本

    按vue-cli的官方文档中卸载了旧版(2.8.2),然后重装了新版本,之后输入 vue --version还是显示2.8.2,最后发现关闭终端后重新打开终端,再看vue --version显示的是新 ...

  8. 在docker中运行.netcore程序

    安装docker 获取core镜像 docker pull microsoft/dotnet 首先在https://hub.docker.com查找core官方镜像,相关参数设置https://hub ...

  9. sunset

    may there be enough clouds in your life to make a beautiful sunset

  10. mysql5.7 timestamp错误:there can be only oneTIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE

    #1293 - Incorrect table definition; there can be only oneTIMESTAMP column with CURRENT_TIMESTAMP in ...