PTA 1001 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 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的更多相关文章
- 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 ...
- 1001.A+B Format (20)代码自查(补足版)
1001.A+B Format (20)代码自查(补足版) 谢谢畅畅酱的提醒,发现了代码中的不足,把变量名更改成更合理的名字,并且把注释也换成英文啦! 栋哥提供的代码自查的方式也帮助了我发现很多代码中 ...
- PAT甲级 1001 A+B Format
题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 1001 A+B Format ( ...
- 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(10)
1001.A+B Format(20) github链接:[example link](https://github.com/wgc12/object-oriented 1.对题目的理解: 首先这道题 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- NR / 5G - Uplink Carrier Waveform Generation
- Java HashMap 四种遍历方式
HashMap遍历方式包含以下4种: 1.遍历KeySet,再通过Key来getValue. 2.使用entrySet的迭代器. 3.foreach entrySet的方式. 3.foreache v ...
- 记一次kubernetes驱逐踩坑
最近在公司的线上服务器上发现了一个现象: 将某个node的kubelet短暂的停掉之后,其上的pod马上会被驱逐,这让笔者大吃一惊,印象之中,停掉kubelet后,该node会变为NotReady状态 ...
- docker pull 时报错Create more free space in thin pool or use dm.min_free_space option to change behavior
docker pull 时报错: failed to register layer: devmapper: Thin Pool has 107394 free data blocks which is ...
- 兄弟连 企业shell笔试题 16-31
企业实践题16:企业案例:写网络服务独立进程模式下rsync的系统启动脚本 例如:/etc/init.d/rsyncd{start|stop|restart} .要求:1.要使用系统函数库技巧.2.要 ...
- df du 文件空间管理 命令
df 可以查看一级文件夹大小.使用比例.档案系统及其挂入点,但对文件却无能为力. du 可以查看文件及文件夹的大小. df:常用 df -h 以易读形式显示 磁盘空间 linux ...
- chrome报错:您目前无法访问 因为此网站使用了 HSTS
chrome报错:您目前无法访问 因为此网站使用了 HSTS 其然: 现象 :访问github仓库报错'您目前无法访问XXXX 因为此网站使用了 HSTS' 解决方法:清理HSTS的设定,重新获取.c ...
- Jenkins新建节点找不到通过Java web启动代理?
参考博客:Jenkins新建节点,启动方式没有“通过Java Web启动代理”选项怎么办? 在Jenkins中,打开“系统管理”→“管理节点”→“新建节点”页面时,“启动方式”选项没有“通过Java ...
- 【大白话系列】MySQL 学习总结 之 COMPACT 行格式的设计原理
如果大家对我的 [大白话系列]MySQL 学习总结系列 感兴趣的话,可以点击关注一波. 一.回顾 MySQL 学习总结系列至此已经第七节了. 从大方向:我们已经学习了 MySQL 的架构设计.Inno ...
- Nginx之常用基本配置
上一篇博客我们大概介绍了一下nginx,nginx的架构,nginx编译安装和nginx命令的用法,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/1236680 ...