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
 
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
 

解题:

#include<stdio.h>
#include<stdlib.h> int main()
{
int a=0,b=0,sum=0;
scanf("%d %d",&a,&b);
sum=a+b; if(sum/1000000)
{
printf("%d",sum/1000000);
printf(",");
printf("%03d",abs(sum%1000000/1000));
printf(",");
printf("%03d",abs(sum%1000000%1000));
}
if(sum/1000000==0&&sum/1000)
{
printf("%d",sum/1000);
printf(",");
printf("%03d",abs(sum%1000));
}
if(sum/1000000==0&&sum/1000==0)
printf("%d",sum); }

PAT (Advanced Level) Practice 1001 A+B Format 分数 20的更多相关文章

  1. PAT (Advanced Level) Practice 1001 A+B Format (20 分)

    题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 Calculate a+b and ...

  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 Level) Practice 1031 Hello World for U (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642 题目描述: Given any string of N (≥5) ...

  4. PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642 题目描述: Notice that the number ...

  5. PAT (Basic Level) Practice 1032 挖掘机技术哪家强 分数 20

    为了用事实说明挖掘机技术到底哪家强,PAT 组织了一场挖掘机技能大赛.现请你根据比赛结果统计出技术最强的那个学校. 输入格式: 输入在第 1 行给出不超过 105 的正整数 N,即参赛人数.随后 N  ...

  6. PAT (Basic Level) Practice 1024 科学计数法 分数 20

    科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指 ...

  7. PAT (Basic Level) Practice 1017 A除以B 分数 20

    本题要求计算 A/B,其中 A 是不超过 1000 位的正整数,B 是 1 位正整数.你需要输出商数 Q 和余数 R,使得 A=B×Q+R 成立. 输入格式: 输入在一行中依次给出 A 和 B,中间以 ...

  8. PAT (Basic Level) Practice 1033 旧键盘打字 分数 20

    旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及坏掉的那些键,打出的结果文字会是怎样? 输入格式: 输入在 2 行中分别给出坏掉的那些键.以及应该输入 ...

  9. PAT (Basic Level) Practice 1023 组个最小数 分数 20

    给定数字 0-9 各若干个.你可以以任意顺序排列这些数字,但必须全部使用.目标是使得最后得到的数尽可能小(注意 0 不能做首位).例如:给定两个 0,两个 1,三个 5,一个 8,我们得到的最小的数就 ...

随机推荐

  1. 新建 Microsoft Office Word 文档 来源:牛客网

    题目 链接:https://ac.nowcoder.com/acm/contest/28886/1015 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其 ...

  2. 浮点数(UVa11809)题解

    浮点数(UVa11809)题解 如题 计算机常用阶码-尾数的形式保存浮点数.如下所示,若阶码有6位,尾数有8位,可以表达的最大的浮点数为0.1111111112 * 2 ^ 1111112.注意小数点 ...

  3. 用kubeadm简单部署k8s

    一.环境准备 1.三台CentOS6.7虚拟机 master:192.168.0.54 注意:主节点最好是2颗cpu,否则在k8s控制平面初始化的时候会报错: node1:192.168.0.68 n ...

  4. [spring]spring的bean自动装配机制

    7.bean的自动装配 是spring满足bean依赖的一种方式 spring会在上下文中自动寻找,并自动给bean装配属性 spring的装配方式: (1)手动装配 在people类中依赖了cat和 ...

  5. javascript 原生class操作

    <script type="text/javascript"> function hasClass(elements, cName) { return elements ...

  6. php date函数和首位带0问题

    一.带零 echo date('Y-m-d'); 2012-08-08 二.不带零 echo date('Y-n-j'); 2012-8-8 以下为参数详解(转载): a - "am&quo ...

  7. 转:windows下定时执行备份数据库

    上一篇写了linux下定时任务,这一篇转发一个windows下定时备份数据库. 第一种:新建批处理文件 backup.dat,里面输入以下 net stop mysql xcopy "C:\ ...

  8. PhpStorm 中文设置教程

    本文仅供学习交流使用,如侵立删!demo下载见文末 Pycharm中文设置教程 1.首先打开PhpStorm ,点击file-settings.找到plugins,搜索Marketplace,然后搜索 ...

  9. Luogu2439 [SDOI2005]阶梯教室设备利用 (动态规划)

    同上一题,区间改左闭右开就双倍经验了.貌似可以跑最长路. #include <iostream> #include <cstdio> #include <cstring& ...

  10. iommu分析之---DMA remap框架实现

    本文主要介绍iommu的框架.基于4.19.204内核 IOMMU核心框架是管理IOMMU设备的一个通过框架,IOMMU设备通过实现特定的回调函数并将自身注册到IOMMU核心框架中,以此通过IOMMU ...