[PAT]A+B Format[简单]
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[简单]的更多相关文章
- Java format 简单应用
一.前言 String.format 作为文本处理工具,为我们提供强大而丰富的字符串格式化功能,为了不止步于简单调用 String.format("Hello %s", " ...
- PAT 1001A+B Format
Github 1001 题目速览 1.解题的思路过程 认真读题,题目为A+BFormat,简单的计算a+b问题,特殊在于输出的形式. 输入形式为每个输入文件包含一个测试样例,每个测试样例仅包含一对整型 ...
- PAT 1083 List Grades[简单]
1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...
- PAT 1089 狼人杀-简单版(20 分)(代码+测试点分析)
1089 狼人杀-简单版(20 分) 以下文字摘自<灵机一动·好玩的数学>:"狼人杀"游戏分为狼人.好人两大阵营.在一局"狼人杀"游戏中,1 号玩家 ...
- PAT 1132 Cut Integer[简单]
1132 Cut Integer(20 分) Cutting an integer means to cut a K digits lone integer Z into two integers o ...
- PAT 1041 Be Unique[简单]
1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is desi ...
- PAT 1121 Damn Single[简单]
1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...
- PAT 1120 Friend Numbers[简单]
1120 Friend Numbers (20 分) Two integers are called "friend numbers" if they share the same ...
- 第二次作业 编程题 PAT 1001A+B Format
Github的object-oriented仓库:1001.A+BFormat(20) 1.解题的思路过程 在之前学习C语言时曾经碰到过类似的将数字转换成字符输出的情况,这道题目要求输出的数字每三个间 ...
随机推荐
- python函数定义语法总结
见下面代码及注释: def calc(value): sum=0 for m in value: sum=sum+m return sum data=[1,2,3,4,5,6,7,8,9,10] pr ...
- [转]centos6 与 7 其中的一些区别
# vi /etc/ssh/sshd_config #将MaxAuthTries注释去掉 MaxAuthTries 5(登录次数) UseDNS no 默认是yes 的,把这个改为no,可以大大减 ...
- RedHat 简易配置 VNC Server 与VNC View详细说明
首先下载Linux版本的VNC文件. 下载地址:http://www.realvnc.com/download/vnc/ 如:VNC-5.0.2-Linux-x86-RPM.tar.gz(其实解压出来 ...
- java.lang.instrument 中的premain 实现类的个性化加载(附源代码)
背景 想调用ASM API (用于字节码处理的开源API)对字节码进行处理,目标是实现对java程序运行时各种对象的动态跟踪,并进一步分析各个对象之间的关系(研究前提是目前的UML锁阐释的whole- ...
- Sql Server 统计当天数据
方法一. ),日期字段名,)),) 方法二. Access: * FROM 表名 WHERE DAY(日期字段名)=DAY(NOW()) 查询当天之前一天的数据
- 吐槽win8
想吐槽win8好久了!今天终于忍不住,得喷一下以泻心头之愤. 文件拷贝动辄失败!? 但凡是我从远程往本地拷大程序,此时文件系统变得奇慢无比,而且本地也不能打开大文件或者往外拷贝,否则一不小心就出现拷贝 ...
- spring task的定时任务突然断了
spring定时任务只开启一个线程去工作也就是串行工作,定时调度任务出现阻塞导致线程终止 加上这个试试 <!-- <task:annotation-driven /> --> ...
- centos6.9环境下JDK安装
1.准备jdk安装文件: 这里我使用的是 jdk-7u79-linux-x64.tar.gz 2.在 /usr/local 目录下创建 sotfware目录,并上传JDK文件: 解压文件并修改文件夹为 ...
- SSH客户端提示 用户密钥未在远程主机上注册
今天在一台使用已久的内网服务器上面帮一位新同事添加账户,添加完成之后就把账号交付于他,过了10分钟他告诉我说无法登陆,觉得很诧异 这么轻车熟路的 这么会 登陆不上去了,自己也用Xshell 登陆了一下 ...
- 170821、本地代码上传gitlub
第一步:建立git仓库 cd到你的本地项目根目录下,执行git命令 git init #初始化项目 第二步:将项目的所有文件添加到仓库中 git add . 或者git add -A #如果想添加某个 ...