1001 A+B Format (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 Specification:
Each input file contains one test case. Each case contains a pair of integers a and b where −10^6≤a,b≤10^6. 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
分析:注意到a,b的范围可以用int型表示,int可以表示10^9的范围,一开始想复杂了,其实直接把字符串逆置后,从高位输出,每输出3个数字输出一个逗号就行了。
/**
* Copyright(c)
* All rights reserved.
* Author : Mered1th
* Date : 2019-02-24-19.21.16
* Description : A1001
*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<unordered_set>
#include<map>
#include<vector>
#include<set>
using namespace std;
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
int a,b,c;
scanf("%d%d",&a,&b);
c=a+b;
){
printf("-");
c=-c;
}
string s=to_string(c);
reverse(s.begin(),s.end());
int len=s.length();
;i>=;i--){
)%==&&i!=len-&&i>){
printf(",");
}
printf("%c",s[i]);
}
;
}
1001 A+B Format (20 分)的更多相关文章
- PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642
PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642 题目描述: Calculate a+b and output the sum i ...
- PAT Advanced 1001 A+B Format (20 分)
Calculate a+b and output the sum in standard format -- that is, the digits must be separated into gr ...
- PAT甲级——1001 A+B Format (20分)
Calculate a+b and output the sum in standard format – that is, the digits must be separated into gro ...
- PAT 1001 A+B Format (20分) to_string()
题目 Calculate a+b and output the sum in standard format -- that is, the digits must be separated into ...
- 【PAT甲级】1001 A+B Format (20 分)
题意:给两个整数a,b,计算a+b的值并每三位用逗号隔开输出(−1e6≤a,b≤1e6) AAAAAccepted code: #include<bits/stdc++.h> us ...
- 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 ...
- 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 ...
- 1001.A+B Format (20)代码自查(补足版)
1001.A+B Format (20)代码自查(补足版) 谢谢畅畅酱的提醒,发现了代码中的不足,把变量名更改成更合理的名字,并且把注释也换成英文啦! 栋哥提供的代码自查的方式也帮助了我发现很多代码中 ...
- 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 ...
- 关于‘1001.A+B Format (20)’的解题报告
1001.A+B Format(20) 首先要感谢一下指导我github上传问题的小伙伴们,捣腾了一整天我终于摸到了一点门路,真的谢谢你们. 小豪的github 问题描述: Calculate a + ...
随机推荐
- MyEclipse持续性开发教程:用JPA和Spring管理数据(五)
MyEclipse 3.15 Style——在线购买低至75折!火爆开抢>> [MyEclipse最新版下载] 本教程介绍了MyEclipse中的一些基于JPA / Spring的功能.有 ...
- MyEclipse WebSphere开发教程:WebSphere 7安装指南(一)
[周年庆]MyEclipse个人授权 折扣低至冰点!立即开抢>> [MyEclipse最新版下载] 一.先决条件和系统信息 想要使用WebSphere,您必须拥有MyEclipse Blu ...
- 自定义iconfont 图标库下载本地在移动App的使用及svg彩色图标
自定义iconfont 图标库扩展 在Hbuilder开发移动App的使用及svg彩色图标(或mui图标库的自定义扩展) 前提准备:1.登录阿里iconfont图标库,创建自己的项目,地址:http: ...
- select * from v$reserved_words
select * from v$reserved_words 查询库中所有关键字
- NodeJS 难点(网络,文件)的 核心 stream 三:readable ?
什么是可读流 可读流 常见 读取磁盘文件.读取网络请求内容等,看一下前面介绍什么是流用的例子: const rs = fs.createReadStream(filePath); 我们常见的控 ...
- php flock 文件锁
于php中文件锁函数flock函数用法简介,希望通过本文的介绍大家对于Linux方面能够更加的了解 flock (PHP 4, PHP 5) flock — 轻便的咨询文件锁定 说明 bool flo ...
- KBMMW 的日志管理器
kbmmw 4.82 最大的新特性就是增加了 日志管理器. 新的日志管理器实现了不同类型的日志.断言.异常处理.计时等功能. 首先.引用kbmMWLog.pas 单元后,系统就默认生成一个IkbmMW ...
- About RFC
RFC说明 Request For Comments (RFC),是一系列以编号排定的文件,几乎所有的因特网标准都收录在RFC文件之中,如果你想成为网络方面的专家,那么RFC无疑是最重要也是最经常需要 ...
- EXCEL教程,包你一学就会
片名称:自动筛选 照片名称:在Excel中字符替换 照片名称:在Excel中直接编辑“宏” 照片名称:在Excel中为导入外部数据 照片名称:在Excel中行列快速转换 照片名称:在Excel中运行“ ...
- js获取 gps坐标
if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(pos) { model.address. ...