博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT 1001 A+B Format
阅读量:4566 次
发布时间:2019-06-08

本文共 1276 字,大约阅读时间需要 4 分钟。

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 −. 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
#include
#include
#include
#include
using namespace std;typedef long long ll;int main(){ ll a,b; cin >> a >> b; ll c = a+b; if(c == 0){cout << 0;return 0;} if(c<0){ cout << "-"; c = -c; } vector
vec; int cnt = 0; while(c){ if(cnt%3 == 0)vec.push_back(-1); vec.push_back(c%10); c = c/10; cnt++; } for(int i=vec.size()-1;i>0;i--){ if(vec[i]==-1)cout << ","; else cout << vec[i]; }// for(auto num:vec) cout << num << " "; return 0;}

都用leetcode风格写,nice!

 

转载于:https://www.cnblogs.com/cunyusup/p/10663767.html

你可能感兴趣的文章
基于ArcGIS JS API的在线专题地图实现
查看>>
learnByWork
查看>>
lua 函数
查看>>
Git的基本命令
查看>>
四平方和
查看>>
第十八周 12.27-1.2
查看>>
C# IP地址字符串和数值转换
查看>>
TCHAR和CHAR类型的互转
查看>>
常用界面布局
查看>>
C语言—— for 循环
查看>>
IBM lotus9.0测试版即将公测
查看>>
xml常用方法
查看>>
Cube Stacking(并差集深度+结点个数)
查看>>
AndroidStudio3更改包名失败
查看>>
jq 删除数组中的元素
查看>>
js URL中文传参乱码
查看>>
Leetcode 367. Valid Perfect Square
查看>>
UVALive 3635 Pie(二分法)
查看>>
win系统查看自己电脑IP
查看>>
Backup&recovery备份和还原 mysql
查看>>