问题描述:

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

没啥难的,水一篇罢了,帮狗子同学改的代码,缩进没改。


代码:

 #include <iostream>
#include <cmath>
using namespace std;
int main()
{
int a,b,sum=;
long x;
char num[]={};
cin>>a>>b;
x=a+b;
if (x>){
while (x!=)
{
num[sum]=x%+;
x=x/;
sum++;
}
for (int i=sum-;i>=;i--)
{
cout<<num[i];
if (i%==&&i!=)
cout<<",";
}}
else if (x==)
cout<<"";
else
{
while (x!=)
{
num[sum]=abs(x%)+;
x=x/;
sum++;
}
cout<<"-";
for (int i=sum-;i>=;i--)
{
cout<<num[i];
if (i%==&&i!=)
cout<<",";
}}
return ;
}

PTA 1001 A+B Format的更多相关文章

  1. PTA (Advanced Level) 1001 A+B Format

    1001 A+B Format Calculate a+b and output the sum in standard format -- that is, the digits must be s ...

  2. 1001.A+B Format (20)代码自查(补足版)

    1001.A+B Format (20)代码自查(补足版) 谢谢畅畅酱的提醒,发现了代码中的不足,把变量名更改成更合理的名字,并且把注释也换成英文啦! 栋哥提供的代码自查的方式也帮助了我发现很多代码中 ...

  3. PAT甲级 1001 A+B Format

    题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 1001 A+B Format ( ...

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

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

  6. 1001.A+B Format(10)

    1001.A+B Format(20) github链接:[example link](https://github.com/wgc12/object-oriented 1.对题目的理解: 首先这道题 ...

  7. PAT 1001. A+B Format 解题

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

  8. 1001 A+B Format (20 分)

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

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

随机推荐

  1. JS代码格式化时间戳

    一.[24小时制]yyyy-MM-dd HH:mm:ss new Date().toJSON() // 2019-12-13T13:12:32.265Z 通过上面的方法,基本就可以将日期格式化,然后稍 ...

  2. Markdown编写接口文档模版

    接口名称 1) 请求地址 https://apis.cnblogs.com/user/info?a=xx&b=xx 2) 调用方式:HTTP GET 3) 接口描述: 接口描述详情 4) 请求 ...

  3. 大文件切割(split)

    split提供两种方式对文件进行切割: 根据行数切割,通过-l参数指定需要切割的行数 根据大小切割,通过-b参数指定需要切割的大小 1.1 根据行数切割 如下以一个3.4G大小的日志文件做切割演示,每 ...

  4. css架构技巧

    1. 写一个reset.css 用于清除浏览器标签默认样式并定义全局样式,这样就不会因为浏览器默认样式出现问题,因为不同浏览器的默认样式还是不一样的

  5. .NET Core MVC 静态文件应用

    一.静态文件应用方面 ASP.NET Core 静态文件应用,主要分为两方面:网站访问和静态文件整合 二.案例 1.访问静态文件 我们都知道,在 ASP.NET 项目中,我们的静态文件一般要放在 ww ...

  6. Python3标准库:weakref对象的非永久引用

    1. weakref对象的非永久引用 weakref模块支持对象的弱引用.正常的引用会增加对象的引用数,并避免它被垃圾回收.但结果并不总是如期望中的那样,比如有时可能会出现一个循环引用,或者有时需要内 ...

  7. fish 设置环境变量;fish shell 相关使用说明记录;

    最近使用 fish进行工作,发现环境变量忘记如何设置: fish 环境变量保存在两个地方: ~ 目录下,.config/fish 目录下: /etc/fish/ 目录下 如果配置所有用户都能用的环境变 ...

  8. 【Android】安卓Q适配指南-相册

    碎碎念 本来每次安卓版本升级都是非常期待的事情,但是开发者就吃苦了!!! 尤其是从Q开始,应用采用沙盒模式,即各种公共文件的访问都会受到限制... 所以适配Q成了当务之急,然鹅网上关于适配的资料少之又 ...

  9. Q&A in 2018 - Q2

    How to zip a file for Windows? 压缩一个文件: makecab c:/file_name.txt c:/file_name.zip 解压一个文件: expand c:/f ...

  10. P2746 [USACO5.3]校园网Network of Schools [tarjan缩点]

    题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作“接受学校”).注意即使 BB 在 AA 学校的分发列表中,AA 也不一定在 BB 学校的列表中. ...