PAT甲级 1001 A+B Format
题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400
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 −106≤a,b≤106. 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
AC代码:
#include <iostream>
#include<cstdio>
using namespace std;
int main(int argc, char const *argv[])
{
int a, b;
cin >> a >> b; int c = a + b;
if (a + b < ) {
cout << "-";
c = -c;
}
if (c >= ) {
printf("%d,%03d,%03d\n", c / , c % / , c % ); } else if (c >= ) {
printf("%d,%03d\n", c / , c % );
} else {
printf("%d\n", c );
} return ;
}
PAT甲级 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 ...
- PAT甲级 1001. A+B Format (20)
题目原文: Calculate a + b and output the sum in standard format -- that is, the digits must be separated ...
- PAT 甲级 1001 A+B Format
https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 Calculate a + b and ou ...
- 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) 2016-09-09 22:47 25人阅读 评论(0) 收藏
1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calculate ...
- 【PAT】1001. A+B Format (20)
1001. A+B Format (20) Calculate a + b and output the sum in standard format -- that is, the digits m ...
- 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水题飘过
#include<iostream> using namespace std; int main(){ int a, b; while(scanf("%d%d", &a ...
随机推荐
- IDLE清屏扩展
新建ClearWindows.py,复制以下代码: class ClearWindow: menudefs = [ ('options', [None, ('Clear Shell Window', ...
- JS 自由变量---JS 学习笔记(三) 补充
自由变量:在 A 中作用域要用到的变量 x,并没有在 A 中声明,要到别的作用域中找到他,这个变量 x 就是自由变量.代码示例如下: var x = 20; function A (b) { ret ...
- Kotlin 继承
Kotlin 中所有类都继承该 Any 类,它是所有类的超类,对于没有超类型声明的类是默认超类: class Example // 从 Any 隐式继承 Any 默认提供了三个函数: equals() ...
- UI组件--element-ui合计行在横向滚动条下面的解决方法
使用element-ui合计功能, 因列数较多, 产生横向滚动条: 但是合计行却在滚动条下面, 拖动滚动条合计行不会跟着横向滚动. 在当前页面添加以下样式: <style lang='less' ...
- 第 9 章 数据管理 - 077 - 跨主机使用 Rex-Ray volume
跨主机使用 Rex-Ray volume 在docker1上创建mysql容器,并挂载使用mysqldata数据卷 磁盘文件直接挂载在了docker1 上 验证数据 也是存在的 Rex-Ray 可以提 ...
- windows下面Nginx日志切割
Nginx本身并不支持日志切割,那么就会造成日志非常的大,为了解决这个问题我们用到了windows的计划任务和dos命令.具体思路: 1.写一个dos文件,通过windows的计划任务定时执行(每天执 ...
- Vue项目使用bootstrap
①npm install boostrap@4.0.0 --save @4.0.0为版本号 ②在项目的main.js中添加 import 'bootstrap/dist/css/bootstrap.m ...
- 将本地文件上传到GitHub
首先,可参见廖雪峰老师的官方网站进行Git安装:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c ...
- C# T 泛型类,泛型方法的约束条件用法
class A<T> where T:new() 这是类型参数约束,where表名了对类型变量T的约束关系.where T:A 表示类型变量是继承于A的,或者是A本省.where T: n ...
- echarts常用方法,饼图切换圆环中文字(三)
在echarts的饼图应用时,遇到过一个需求就是鼠标移到半环上可以切换环中的文字,同时支持legend点击事件.误区是,鼠标移动到环上重新渲染option,以切换内部的文字.重新渲染option的做法 ...