1001 A+B Format
由于逗号的有无是从末尾数起,满足三个数(且高位还有数)就加逗号,所以有必要把字符串反转,然后寻找数组下标和3的关系
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;int main(){long long a,b;scanf("%lld %lld",&a,&b);char sumStr[10]="";sprintf(sumStr,"%lld",a+b);int lenStr = strlen(sumStr);int lenNum;//去掉符号后的长度 if(sumStr[0] == '-'){printf("-");lenNum = lenStr - 1;}else{lenNum = lenStr;}//-999991//-2,000,000//-22char revStr[10] = "";//将字符串倒转过来 for(int i=0;i<lenNum;i++){revStr[i] = sumStr[lenStr-1-i];}for(int i=lenNum-1;i>=0;i--){if((i+1)%3 ==0&&i!=lenNum-1){printf(",");}printf("%c",revStr[i]);} return 0;
}
1001 A+B Format相关推荐
- Pat甲级 1001 A+B Format
Pat甲级 1001 A+B Format 思路 代码 题目网址 https://pintia.cn/problem-sets/994805342720868352/problems/99480552 ...
- PAT甲级1001 A+B Format:[C++题解]字符串处理
文章目录 题目分析 题目链接 题目分析 数字转化成string 的函数to_string() 倒序遍历string,还保证原来的顺序需要 res = num[i] +res. 这里的加号不是数字运算, ...
- 【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 ...
- 题目1001 A+B Format
记录学习写博客的第一天(PAT题目) 题目1001 A+B Format Calculate a+b and output the sum in standard format – that is, ...
- PAT-PAT (Advanced Level) Practise 1001. A+B Format (20) 【二星级】
题目链接:http://www.patest.cn/contests/pat-a-practise/1001 题面: 1001. A+B Format (20) Calculate a + b and ...
- 1001 A+B Format (20分)——12行代码AC
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Calculate a+b and output the sum in standard format – that is, th ...
- 1001 A+B Format (20point(s))(Java和C++)
文章目录 Java版 C++版 Calculate a+b and output the sum in standard format – that is, the digits must be se ...
- PAT (Advanced Level) Practise:1001. A+B Format
[题目链接] Calculate a + b and output the sum in standard format -- that is, the digits must be separate ...
- (甲)1001 A+B Format (20 分)
题目: Calculate a+b and output the sum in standard format -- that is, the digits must be separated int ...
- 【PAT】1001. A+B Format
http://pat.zju.edu.cn/contests/pat-a-practise/1001 此题花费了很长时间,做了几次都是说超时,网上找了个答案找到毛病,while(true)是绝对不能用 ...
最新文章
- PVANET: Deep but Lightweight Neural Networks for Real-time Object Detection
- 搭建TXManager分布式事务协调者
- 很认真地聊一下 “选择比努力更重要”
- GitHub的CI实践(xUnit / OpenCover /Appveyor / Coveralls.net)
- react回调函数_React中的回调中自动绑定ES6类函数
- android 底部动画,Android实现360手机助手底部的动画菜单
- 【Elasticsearch】Elasticsearch 的异步搜索原理解析 _async_search
- 目前最小的替换模板了,只有十几行代码
- params参数的调用
- 初学者虚拟机使用虚拟机
- [笔记二]Essential JavaScript Design Patterns For Beginners
- vncviewer退出全屏
- 2023电工杯数学建模A题思路
- JAVA编写 飞翔的小鸟
- 【PM必知】项目管理的“六大核心”内容详解
- 《第四期(2021-2022)传统行业云原生技术落地调研报告——金融篇》正式发布
- 江西理工大学理学院计算机,2016年江西理工大学理学院计算机科学与技术(加试)之C程序设计复试笔试最后押题五套卷...
- 8个Spring事务失效的场景,你碰到过几种?
- 价值为纲:华为财经管理
- 提升视频监控效能 纵横网络有效防控