Pat甲级 1001 A+B Format
Pat甲级 1001 A+B Format
- 思路
- 代码
题目网址
https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400
思路
a+b按照一定格式输出,都不是大数,直接加就完事儿了,注意下结果为0的情况就好.我的代码是为了练习vector容器特意写成这样的,更简单的思路应该是把相加的数字转为string,然后判断输出逗号.
代码
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>using namespace std;vector<char> v;int main() {int a;int b;int sum;int cnt = 1;cin >> a >> b;sum = a + b;if (sum < 0)cout << "-";sum = abs(sum);if (sum == 0) {cout << 0 << endl;return 0;}while (sum > 0) {int t = sum % 10;sum /= 10;v.push_back(t + '0');if (cnt == 3) {v.push_back(',');cnt = 0;}cnt ++;}if (v.back() == ',')v.pop_back();reverse(v.begin(), v.end());for (auto i : v)cout << i;return 0;
}
}
Pat甲级 1001 A+B Format相关推荐
- PAT甲级1001 A+B Format:[C++题解]字符串处理
文章目录 题目分析 题目链接 题目分析 数字转化成string 的函数to_string() 倒序遍历string,还保证原来的顺序需要 res = num[i] +res. 这里的加号不是数字运算, ...
- PAT甲级1001.A+B Format(20)
---恢复内容开始--- 题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 对于该题 ...
- PAT甲级1001~1025
PAT甲级1001~1025 1001 A+B Format (20 分) 1002 A+B for Polynomials (25 分) 1003 Emergency (25 分) 1004 Cou ...
- PAT甲级1001 字符串处理
题目 1001 A+B Format (20 分) Calculate a+b and output the sum in standard format – that is, the digits ...
- 【PAT】1001. A+B Format
http://pat.zju.edu.cn/contests/pat-a-practise/1001 此题花费了很长时间,做了几次都是说超时,网上找了个答案找到毛病,while(true)是绝对不能用 ...
- PTA 甲级 1001 A+B Format (20分)
这题我不会,是抄的刘婼大神的.地址如下 地址 #include <iostream> #include<string> using namespace std; int mai ...
- 【PAT甲级】字符串处理及进制转换专题
目录 字符串处理 PAT甲级 1001 A+B Format (20 分) PAT甲级1005 Spell It Right (20 分) PAT甲级1035 Password (20 分) PAT甲 ...
- 【PAT甲】1001 A+B Format (20分) 格式化输出
problem 1001 A+B Format (20分) Calculate a+b and output the sum in standard format – that is, the dig ...
- PAT甲级训练合集(1-70)
本章题解跳转 考点 P1001 数字的数组表示和处理 P1002 多项式的数组表示和处理 P1003 深度优先搜素 P1004 深度优先搜素 P1005 哈希表 P1006 P1007 数组子区间求和 ...
最新文章
- 更改Jenkins升级站点
- K-means算法详解及python代码实现
- mysql 横向分表合并_MySQL横向扩展-分库分表解决方案总结
- 老刘说NLP:焦虑被大肆贩卖下的自然语言处理学习思考
- asp.net页面中Menu控件下拉菜单被frame挡住和iframe自适应高度的解决办法
- winscp自动执行脚本
- html5 background-size,css3 Background-size属性使用说明
- windows7安装cuda10.2
- 开学作业——如何做好课堂笔记
- Transmission搭建BT下载服务器
- typora中的图片加载不出来
- swift 打开第三方应用_Swift常用第三方
- c语言五子棋最简单的ai,C++简单五子棋的AI设计实现
- ArcGIS软件CAD数据通过转换建立GIS数据库
- WIN7 启动屏幕键盘
- 微信微网站的服务器ip地址查询,微信开发之(三)获取微信服务器IP地址
- 透明木头问世!“木头大王”胡良兵再发顶刊,已成立公司加速落地
- phpstudy 404页面设置 也就是Apache404页面的设置
- 适合职中计算机专业一年级书,职中一年级计算机基础试题.doc
- Python简明手册-转自啄木鸟社区
热门文章
- 什么时候会引起索引失效
- 016_html段落
- 算术运算符举例java_Java的算术运算符简介
- Activity、View、Window、DecorView的关系
- Java数据结构和算法:图
- 安卓自定义View进阶-Matrix Camera
- linux 系统打造man中文帮助手册图解
- 向量距离计算 java_Milvus 向量搜索引擎开源了!
- maya绑定控制器在大纲里是灰色的_3dsmax绑定转maya ADV插件
- firefox如何不让网站登录失效_Firefox Preview 4开放下载:引入登录管理、热门网站等功能...