1001 A+B Format (20)(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

Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.

Output

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<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
using namespace std;
char s[];
int main()
{
int a,b;
cin>>a>>b;
a=a+b;
int start=;
int temp,len=;
b=a;
if(a<)a=-a;
if(a==)cout<<;
while(a){
temp=a%;
a/=; len++;
if(len>&&len%==)
s[start++]=',';
s[start++]=temp+'';
}
if(b<)
cout<<'-'; for(int i=start-;i>=;i--)
cout<<s[i];
return ;
}

//就是求a+b的和,并且输出。非常简单。并且和都不会溢出int.第一次提交的时候只得了19分,发现是因为在输入两个0时,程序没有输出。之后对两者和进行判断,若和为0,直接输出0即可。

[PAT]A+B Format[简单]的更多相关文章

  1. Java format 简单应用

    一.前言 String.format 作为文本处理工具,为我们提供强大而丰富的字符串格式化功能,为了不止步于简单调用 String.format("Hello %s", " ...

  2. PAT 1001A+B Format

    Github 1001 题目速览 1.解题的思路过程 认真读题,题目为A+BFormat,简单的计算a+b问题,特殊在于输出的形式. 输入形式为每个输入文件包含一个测试样例,每个测试样例仅包含一对整型 ...

  3. PAT 1083 List Grades[简单]

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

  4. PAT 1089 狼人杀-简单版(20 分)(代码+测试点分析)

    1089 狼人杀-简单版(20 分) 以下文字摘自<灵机一动·好玩的数学>:"狼人杀"游戏分为狼人.好人两大阵营.在一局"狼人杀"游戏中,1 号玩家 ...

  5. PAT 1132 Cut Integer[简单]

    1132 Cut Integer(20 分) Cutting an integer means to cut a K digits lone integer Z into two integers o ...

  6. PAT 1041 Be Unique[简单]

    1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is desi ...

  7. PAT 1121 Damn Single[简单]

    1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...

  8. PAT 1120 Friend Numbers[简单]

    1120 Friend Numbers (20 分) Two integers are called "friend numbers" if they share the same ...

  9. 第二次作业 编程题 PAT 1001A+B Format

    Github的object-oriented仓库:1001.A+BFormat(20) 1.解题的思路过程 在之前学习C语言时曾经碰到过类似的将数字转换成字符输出的情况,这道题目要求输出的数字每三个间 ...

随机推荐

  1. 怎样更改SQL Server 2008的身份验证方式

    大家都知道sql server 有两种登录验证方式,即sql server验证方式和windows验证方式,但是sql server默认的是windows登录验证方式,我们如何启用sql server ...

  2. Esper学习之十五:Pattern(二)

    上一篇开始了新一轮语法——Pattern的讲解,一开始为大家普及了几个基础知识,其中有说到操作符.当时只是把它们都列举出来了,所以今天这篇就是专门详解这些操作符的,但是由于篇幅限制,本篇先会讲几个,剩 ...

  3. c++ istream转换为std::string

    std::istreambuf_iterator<char> eos; std::string s(std::istreambuf_iterator<char>(stream) ...

  4. javascript prototype学习

    function foo(a, b, c) { return a*b*c; } alert(foo.length); alert(typeof foo.constructor); alert(type ...

  5. Testlink自动执行用例小程序

    记得原来在一个公司时,具体很多原因,testlink上项目中的用例都需要执行形成漂亮的报告,但实际测试中又不需要去执行,所以就必须将用例根据上一次测试报告一个一个手工去贴结果刷用例,几百条用例,几天就 ...

  6. 解决Android 5.0中出现的警告:Service Intent must be explicit

    extends:http://www.eoeandroid.com/thread-568853-1-1.html 本帖最后由 469874851 于 2015-3-11 18:15 编辑 有些时候我们 ...

  7. iOS - viewDidLoad, viewWillDisappear, viewWillAppear区别及加载顺序

    viewWillAppear: Called when the view is about to made visible. Default does nothing视图即将可见时调用.默认情况下不执 ...

  8. MPU6050滤波、姿态融合(一阶互补、卡尔曼)

    前几天做了6050原始数据的串口输出和上位机波形的查看.这篇博客我们来看一下对原始数据的处理. 任务:利用STC89C52RC对MPU6050原始数据进行滤波与姿态融合. 首先我摘抄了一段别人在昨晚这 ...

  9. vue中打包生成可配置文件以便修改接口地址

    vue打包上传到服务器之后,如果数据接口域名发生变化,需要手动修改接口地址,在发布的时候也麻烦,于是.. 在打包之后如果有一个json配置文件以便修改那不是方便很多 在网上找了一些方法貌似都是异步请求 ...

  10. Redis的启动过程

    本文主要介绍Redis启动加载过程,总体上可以分为如下几步: 1. 初始化全局服务器配置 2. 加载配置文件(如果指定了配置文件,否则使用默认配置) 3. 初始化服务器 4. 加载数据库 5. 网络监 ...