A1001. A+B Format
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<cstdio>
#include<iostream>
#include<string.h>
using namespace std;
int main(){
int a, b, c, sign = , bt;
char prt[];
scanf("%d%d", &a, &b);
c = a + b;
if(c < ){
c = - * c;
sign =;
}
int i = , tag = ;
do{
bt = c % ;
c = c / ;
prt[i++] = '' + bt;
tag++;
if(tag != && tag % == ){
prt[i++] = ',';
}
}while(c != );
if(prt[i - ] != ',')
prt[i] = '\0';
else
prt[i - ] = '\0';
if(sign == )
printf("-");
for(int j = strlen(prt) - ; j >= ; j--)
printf("%c", prt[j]);
cin >> a;
return ;
}
注意:在整个数字的最高位前不能有逗号。
A1001. A+B Format的更多相关文章
- PAT A1001 A+B Format
		Calculate a+b and output the sum in standard format -- that is, the digits must be separated into gr ... 
- PAT A1001 A+B Format (20 分)
		AC代码 #include <cstdio> #include <algorithm> using namespace std; const int maxn = 11; in ... 
- PTA A1001&A1002
		从今天起每天刷1-2题PAT甲级 第一天 A1001 A+B Format (20 分) 题目内容 Calculate a+b and output the sum in standard forma ... 
- PAT/字符串处理习题集(二)
		B1024. 科学计数法 (20) Description: 科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+ ... 
- PAT题目AC汇总(待补全)
		题目AC汇总 甲级AC PAT A1001 A+B Format (20 分) PAT A1002 A+B for Polynomials(25) PAT A1005 Spell It Right ( ... 
- 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 ... 
- Spring resource bundle多语言,单引号format异常
		Spring resource bundle多语言,单引号format异常 前言 十一假期被通知出现大bug,然后发现是多语言翻译问题.法语中有很多单引号,单引号在format的时候出现无法匹配问题. ... 
- c# 字符串连接使用“+”和string.format格式化两种方式
		参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ... 
- PAT甲级 1001. A+B Format (20)
		题目原文: Calculate a + b and output the sum in standard format -- that is, the digits must be separated ... 
随机推荐
- SpringBoot日记——分布式篇
			思考:什么是分布式?什么是微服务? 一些概念:RPC-远程过程调用,某台机器想要调用另一台机器所需要的一种服务,及分布式的服务框架,比如dubbo或者SpringCloud. 铺天盖地的分布式互联网系 ... 
- Awesome Python,Python的框架集合
			Awesome Python A curated list of awesome Python frameworks, libraries and software. Inspired by awes ... 
- 从源码的角度看 React JS 中批量更新 State 的策略(上)
			在之前的文章「深入理解 React JS 中的 setState」与 「从源码的角度再看 React JS 中的 setState」 中,我们分别看到了 React JS 中 setState 的异步 ... 
- 线上mongodb 数据库用户到期时间修改的操作记录
			登陆版权数据库,显示"此用户已到期",数据库使用的是mongodb,顾 需要将此用户的到期时间延长. 解决过程: 1)到网站对应tomcat配置里找出等里mongodb的信息(mo ... 
- 关键字搜索:jQuery过滤器插件fastLiveFilter||显示结果条数
			引用js库 <script src="jquery-1.6.4.min.js"></script> <script src="jquery. ... 
- JS 实现计算一段文字中的字节数,字母数,数字数,行数,汉字数。
			看到了匹配,第一个想到了用正则表达式,哈哈,果然很方便.不过正则表达式高深莫测!我还没有研究明白啊..目前学了点皮毛.代码如下: <!DOCTYPE html PUBLIC "-//W ... 
- Post Tuned Hashing,PTH
			[ACM 2018] Post Tuned Hashing_A New Approach to Indexing High-dimensional Data [paper] [code] Zhendo ... 
- Filter学习:项目第八阶段
			public interface Filter A filter is an object that performs filtering tasks on either the request ... 
- 基础-Math.floor与parseInt区别
			Math.floor只能对一个数向下取整,不能解析字符串 如: Math.floor(1.5) // 1 Math.floor(-2.1) // -3 Math.floor("3" ... 
- MySQL: Connection Refused,调整 mysql.ini中的 max_connections
			连接相同的结构的MySQL数据库,一套库Tomcat启动正常,另一套库一直报Connection Refused. 可以断定是连接数太小了.查找mysql.ini中的 max_connections, ... 
