思路:每三位分割,注意符号,首位不要出现逗号。


AC代码

#include <stdio.h>
#include <algorithm>
using namespace std;

void solve(int c) {
    if(c < 0) printf("-");
    c = abs(c);
    int dig[20];
    int len = 1;
    do{
        dig[len++] = c % 10;
        c /= 10;
    }while(c > 0);
    for(int i = len-1; i > 0; i--) {
        if(i%3 == 0 && i != len-1) printf(",");
        printf("%d", dig[i]);
    }
    printf("\n");
}

int main() {
    int a, b;
    while(scanf("%d%d", &a, &b) != EOF) {
        int c = a + b;
        solve(c);
    }
    return 0;
}

如有不当之处欢迎指出!

PAT1001 A+B Format的更多相关文章

  1. 随笔2 PAT1001.A+B Format (20)

    1001.A+B Format(20) 题目链接 1001.A+B Format (20) C++ 代码 第一次使用markdown,还不是很习惯,现在努力的在适应它 首先这道题我们很容易就可以读懂题 ...

  2. PAT----1001. A+B Format (20)解题过程

    1001. A+B Format (20) github链接 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B Calculate a + b and output t ...

  3. PAT-1001 A+B Format (20 分) 注意零的特例

    Calculate a+b and output the sum in standard format -- that is, the digits must be separated into gr ...

  4. PAT---1001. A+B Format (20)

    #include<stdio.h> int main(){ //定义要读入的两个整数 int a,b; //定义好放拆项用的数组 ]; //读入两个整数 scanf("%d%d& ...

  5. pat甲级题目1001 A+B Format详解

    pat1001 A+B Format (20 分) Calculate a+b and output the sum in standard format -- that is, the digits ...

  6. Spring resource bundle多语言,单引号format异常

    Spring resource bundle多语言,单引号format异常 前言 十一假期被通知出现大bug,然后发现是多语言翻译问题.法语中有很多单引号,单引号在format的时候出现无法匹配问题. ...

  7. c# 字符串连接使用“+”和string.format格式化两种方式

    参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...

  8. PAT甲级 1001. A+B Format (20)

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

  9. Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ...

    Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ... 这个错误是因为有两个相 ...

随机推荐

  1. BFC(块级格式上下文)

    BFC的生成 满足下列css声明之一的元素便会生成BFC 根元素 float的值不为none overflow的值不为visible display的值为inline-block.table-cell ...

  2. spring使用@Cache的简单实现

    基于xml的配置感觉没有注解形式简单明了,咱不考虑了. 进入正题之前先提个疑问,希望知道的人能告诉一下 下述介绍会有这段代码: @Cacheable(value="myCache" ...

  3. JS-使用工厂方法创建对象

    function createPerson(name,age,gender){ //创建新对象 var obj=new Object(); //向对象中添加属性 obj.name=name; obj. ...

  4. 基础知识全面LINUX

    学习Linux系统的重要性应该不用多说,下面我就对Linux的基础知识进行一个全面而又简单的总结.不过建议大家还是装个Linux系统多练习,平时最好只在Linux环境下编程,这样会大有提高. linu ...

  5. VSFTPD 源码安装升级

    /usr/local/sbin/vsd -v cp /usr/local/sbin/vsd /usr/sbin/vsd 制作启动脚本 vim /etc/xinetd.d/vsd disable = y ...

  6. Centos6.5离线安装lsb_release

    参考 http://www.linuxfromscratch.org/blfs/view/systemd/postlfs/lsb-release.html首先在其他电脑下载lsb_release源码地 ...

  7. java中队列Queue的使用

    1.在java5中新增加了java.util.Queue接口,用以支持队列的常见操作.Queue接口与List.Set同一级别,都是继承了Collection接口.Queue使用时要尽量避免Colle ...

  8. Windows Azure Platform Introduction (14) 申请海外的Windows Azure账户

    <Windows Azure Platform 系列文章目录> 本文的最后更新时间为:2017-12-27 本文介绍国内用户,注册和使用海外Azure账户. 前提: 1.需要一个有效的Wi ...

  9. CNN网络架构演进:从LeNet到DenseNet

    卷积神经网络可谓是现在深度学习领域中大红大紫的网络框架,尤其在计算机视觉领域更是一枝独秀.CNN从90年代的LeNet开始,21世纪初沉寂了10年,直到12年AlexNet开始又再焕发第二春,从ZF ...

  10. 深入理解viewport

    这篇文章我已写成pdf,建议直接下载浏览. 链接:https://pan.baidu.com/s/1c4cwd7E 密码:jty1 <对viewport标签的理解> --版权所有 @RYZ ...