PAT甲级1001 字符串处理
题目
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 −10
6
≤a,b≤10
6
. 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>
using namespace std;
int main(){int a,b;cin>> a >> b;string c=to_string(a+b);int len=c.length();for(int i=0;i<len;i++){cout<<c[i];if(c[i]=='-') continue;//这边的单引号尤其要注意,是字符不是字符串if((i+1)%3==len%3&&i!=len-1) cout<<",";}return 0;
}
PAT甲级1001 字符串处理相关推荐
- 【PAT甲级】字符串处理及进制转换专题
目录 字符串处理 PAT甲级 1001 A+B Format (20 分) PAT甲级1005 Spell It Right (20 分) PAT甲级1035 Password (20 分) PAT甲 ...
- Pat甲级 1001 A+B Format
Pat甲级 1001 A+B Format 思路 代码 题目网址 https://pintia.cn/problem-sets/994805342720868352/problems/99480552 ...
- PAT甲级1001~1025
PAT甲级1001~1025 1001 A+B Format (20 分) 1002 A+B for Polynomials (25 分) 1003 Emergency (25 分) 1004 Cou ...
- PAT甲级1001 A+B Format:[C++题解]字符串处理
文章目录 题目分析 题目链接 题目分析 数字转化成string 的函数to_string() 倒序遍历string,还保证原来的顺序需要 res = num[i] +res. 这里的加号不是数字运算, ...
- 【PAT甲级 删除字符串中的指定字符】1050 String Subtraction (20 分) C++
题目 删除字符串中的另一个字符串包含的所有字符. 可以通过判断两个字符串是否为空,来稍微优化一下运行速度 题解C++ #include<iostream> #include<stri ...
- PAT甲级1005 字符串的处理
题目 Given a non-negative integer N, your task is to compute the sum of all the digits of N, and outpu ...
- PAT甲级1001.A+B Format(20)
---恢复内容开始--- 题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 对于该题 ...
- 【PAT甲级 删除字符串中重复字母】1084 Broken Keyboard (20 分) Java 全部AC
题目 题解 Java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamRead ...
- PAT甲级1108 Finding Average :[C++题解]stof、字符串变成浮点数、try和catch捕获异常、C++语法题
文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: C++中有函数stoi表示把string 变成int,还有函数stof,表示把string变成float.如果是合法数字的话,sto ...
最新文章
- ant自动打包多个android项目为apk
- ios html cookies,iOS-WKWebView携带cookie发送http请求,cookie失效
- Unity动态对象优化
- windows下配置mysql允许远程访问
- [UVa 122] Trees On the Level
- 从html富文本中提取纯文本
- 华为交换机 tagged 与 untagged 的关系、H5C 开web管理、telnet管理
- linux安装时mbr转gpt分区表,免重装系统 手把手教你MBR转GPT分区表
- 如何利用github打造博客专属域名
- 新增spring Converter解析器中使用lambda表达式代替匿名内部类是启动报错:... does the class parameterize those types?
- 图像处理实践 | 水果图像的识别与分类
- 03_Snaker流程demo
- 程雷被机器人_机器人登台表演节目?程雷惨遭机器人戏耍郭德纲一旁大笑!
- 19.Oracle数据库SQL开发之 笛卡尔积
- 计算机财务管理系统基础知识,计算机财务管理实习报告
- 微搭医美美容小程序官方模板解析
- react-dom.development.js:6202 Unable to preventDefault inside passive event listener invocation 错误
- 剑指offer面试题(11-20)——java实现
- 第 3 章 基本数据类型
- 快递100 实时查询
热门文章
- mysql主主同步稳定吗_MySQL主主同步
- html设置长宽高代码_Jenkins CI 自动构建与 CSTAT 代码
- android textview adapter,Android在FragmentPagerAdapter中的Fragment中设置TextView文本
- CString::Format出现的Buffer too small错误
- Storm目录树和任务提交过程
- Pattern Recognition for Cell-free DNA - Github
- [Linux日记]解决Ubuntu升级出现/boot空间不足问题
- python 中self
- Navigation + Tab Bar 常用组合框架
- 安全维护上最不应该犯的十个基本错误