由于逗号的有无是从末尾数起,满足三个数(且高位还有数)就加逗号,所以有必要把字符串反转,然后寻找数组下标和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相关推荐

  1. Pat甲级 1001 A+B Format

    Pat甲级 1001 A+B Format 思路 代码 题目网址 https://pintia.cn/problem-sets/994805342720868352/problems/99480552 ...

  2. PAT甲级1001 A+B Format:[C++题解]字符串处理

    文章目录 题目分析 题目链接 题目分析 数字转化成string 的函数to_string() 倒序遍历string,还保证原来的顺序需要 res = num[i] +res. 这里的加号不是数字运算, ...

  3. 【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 ...

  4. 题目1001 A+B Format

    记录学习写博客的第一天(PAT题目) 题目1001 A+B Format Calculate a+b and output the sum in standard format – that is, ...

  5. 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 ...

  6. 1001 A+B Format (20分)——12行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Calculate a+b and output the sum in standard format – that is, th ...

  7. 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 ...

  8. 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 ...

  9. (甲)1001 A+B Format (20 分)

    题目: Calculate a+b and output the sum in standard format -- that is, the digits must be separated int ...

  10. 【PAT】1001. A+B Format

    http://pat.zju.edu.cn/contests/pat-a-practise/1001 此题花费了很长时间,做了几次都是说超时,网上找了个答案找到毛病,while(true)是绝对不能用 ...

最新文章

  1. PVANET: Deep but Lightweight Neural Networks for Real-time Object Detection
  2. 搭建TXManager分布式事务协调者
  3. 很认真地聊一下 “选择比努力更重要”
  4. GitHub的CI实践(xUnit / OpenCover /Appveyor / Coveralls.net)
  5. react回调函数_React中的回调中自动绑定ES6类函数
  6. android 底部动画,Android实现360手机助手底部的动画菜单
  7. 【Elasticsearch】Elasticsearch 的异步搜索原理解析 _async_search
  8. 目前最小的替换模板了,只有十几行代码
  9. params参数的调用
  10. 初学者虚拟机使用虚拟机
  11. [笔记二]Essential JavaScript Design Patterns For Beginners
  12. vncviewer退出全屏
  13. 2023电工杯数学建模A题思路
  14. JAVA编写 飞翔的小鸟
  15. 【PM必知】项目管理的“六大核心”内容详解
  16. 《第四期(2021-2022)传统行业云原生技术落地调研报告——金融篇》正式发布
  17. 江西理工大学理学院计算机,2016年江西理工大学理学院计算机科学与技术(加试)之C程序设计复试笔试最后押题五套卷...
  18. 8个Spring事务失效的场景,你碰到过几种?
  19. 价值为纲:华为财经管理
  20. 提升视频监控效能 纵横网络有效防控

热门文章

  1. swift -charts框架雷达图
  2. Linux下的redis的持久化,主从同步及哨兵
  3. Yii2.0 RESTful API 之版本控制
  4. MySQL , MHA , Haproxy 配置
  5. 【Java学习笔记之五】java数组详解
  6. 深证信息等三方拟联合开展大数据研究
  7. rpcgen的简单讲解及例子程序
  8. 黑马程序员之List--队列、栈...
  9. mass Framework event模块 v4
  10. Swift2.0系列]Error Handling(项目应用篇)