问题描述:

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. 轻松搞懂Python递归函数的原理与应用

    递归: 在函数的定义中,函数内部的语句调用函数本身. 1.递归的原理 学习任何计算机语言过程中,“递归”一直是所有人心中的疼.不知你是否听过这个冷笑话:“一个面包,走着走着饿了,于是就把自己吃了”. ...

  2. C++括号匹配检测(用栈)

    输入一串括号,包括圆括号和方括号,()[],判断是否匹配,即([]())或[([][])]为匹配的正确的格式,[(])或([())为不匹配的格式. #include<iostream> # ...

  3. javascript 客户端webSocket示例

    //html <script> // 初始化一个 WebSocket 对象 var ws = new WebSocket("ws://localhost:9998/echo&qu ...

  4. win10CPU版TensorFlow安装详细流程(踩N个坑之后的总结)

    版本说明: 多次实验后,python3.5+TensorFlow1.2+numpy1.16.4比较成功,不会报奇奇怪怪的错.(安装流程中会说到,不需要提前下载) 准备工作: 找到电脑:C:\Users ...

  5. redis基础知识汇总

  6. zabbix 自定义监控项报警给单独的人

    需求就是某个交换机的流量达到某个值后需要报警,但报警的内容不是发给所有的人,而是只发给特定的一个人,而其他的报警信息不能让他收到,他只能收到这一个报警项的报警 1:创建好用户定义好手机号 2:新增加一 ...

  7. 优雅地使用 C++ 制作表格:tabulate

    作者:HelloGitHub-ChungZH 0x00 介绍 tabulate tabulate 是一个使用 C++ 17 编写的库,它可以制作表格.使用它,把表格对齐.格式化和着色,不在话下!你甚至 ...

  8. Class Literal(Java)

    前言 上一节我们讨论过通过关键字synchronized实现线程同步,同时最主要了解到在Java中className.class所代表的具体含义,在博客写完后,感觉还是有点迷糊,然后再次深入了解后,原 ...

  9. Ajax0001:ajax介绍 JSON数据处理

  10. idea创建基于maven的web项目

    1.点击create new project,选择maven,点击next 2.输入项目信息,点击finish 3.进入项目后,点击菜单File->Project Structure开始配置项目 ...