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 ...
随机推荐
- Chrome恢复显示网址 https:// 和 www
文章来自我的博客: https://blog.ljyngup.com/archives/686.html/ Chrome这个新规弄得我也很蛋疼,每次一点输入框就突然突出来一下.后来在Hostloc论坛 ...
- Hapi+MySql项目实战数据库操作(四)
数据库访问 下面以Node的ORM框架Sequelize来操作数据库,Mysql为例. 配置数据库连接信息config/db_config.js: //db_config.js module.expo ...
- Linux 配置ip 子接口 多网卡绑定
linux系统配置ip地址,图形化界面略过,这里只介绍文本行.做以下设置注意是否有此权限 查看当前路由及网关信息: [root@localhost ~]# netstat -r Kernel IP r ...
- 前端开发:这10个Chrome扩展你不得不知
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 原文出处:https://blog.bitsrc.io/10-top-chrome-extensions-f ...
- 作为一个Java工程师,你应该要知道SPI机制
什么是 SPI SPI是Service Provider Interface的简称,是JDK默认提供的一种将接口和实现类进行分离的机制.这种机制能将接口和实现进行解耦,大大提升系统的可扩展性. SPI ...
- JMeter-命令行模式压测
前言 使用非GUI模式,即命令行模式运行jmeter测试脚本能够大大缩减系统资源,今天跟小伙伴们讲一下JMeter如何在命令行模式进行压测吧! 一:配置好JDK和JMeter的环境变量(过程略) 二: ...
- C# DateTime 工具类
项目gitHub地址 点我跳转 今天给大家带来一个C#里面的时间工具类,具体的直接看下面代码 using System; namespace ToolBox.DateTimeTool { public ...
- 14.Android-使用sendMessage线程之间通信
1.Handler介绍 Handler 是一个消息分发对象.handler是Android给我们提供用来更新UI的一套机制,也是一套消息处理机制,通过它可以实现在不同线程之间传递消息 本章Handle ...
- Android中实现照片滑动时左右进出的动画的xml代码
场景 Android中通过ImageSwitcher实现相册滑动查看照片功能(附代码下载): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/det ...
- maven导入sqlserver驱动jar包依赖包到本地仓库
maven导入sqlserver驱动jar包依赖包到本地仓库 maven项目使用sqlserver的依赖,先下载一个sqlserver的驱动,网址:https://www.microsoft.com/ ...