1001. A+B Format (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
 

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

Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.

Output

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

主要是题目的groups of three 的of 的用法让我有点迷糊,最后确认是一种属性关系,在题目的意思为3个一组。

代码为:

 /*
 https://www.patest.cn/contests/pat-a-practise/1001
 author: LY   2016.6.26
 */
 #include<iostream>
 #include<string>
 #include<algorithm>
 using namespace std;

 int main()
 {
     int a,b,c;
     string s;
     scanf("%d%d",&a,&b);

      c=a+b;
      ,l=;
      ;   //符号判断
      )
      {
          flag=;
          c=abs(c);
      }
      )!=)
     {
         s[i]=(c%)+';
         c=c/;
         i++;
         l++;
         ==)
             {
                 s[i]=',';
                 i++;
             }
     }
     s[i]= c+';

     //对a+b的和进行拆分(每3个数一组)
     ;
     )
     printf("%c",'-');
     ;j--)
     {
         printf("%c",s[j]);
     } 

     printf("\n");
     ;
 } 

(甲)PAT-1001的更多相关文章

  1. PAT 1001 A+B 解题报告

    PAT 1001 A+B 代码链接:传送门 题目链接:传送门 题目简述: 给定两个值a,b: 范围-1000000 <= a, b <= 1000000: 按指定格式输出a+b的结果,例: ...

  2. PAT 1001 害死人不偿命的(3n+1)猜想 (15)(C++&JAVA&Python)

    1001 害死人不偿命的(3n+1)猜想 (15)(15 分) 卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反 ...

  3. PAT 1001. A+B Format 解题

    GitHub PDF 1001. A+B Format (20) Calculate a + b and output the sum in standard format -- that is, t ...

  4. PAT 1001 A+B Fotmat

    源码 1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calcula ...

  5. PAT 1001 Format

    problem 1001 A+B Format (20)(20 point(s)) Calculate a + b and output the sum in standard format -- t ...

  6. PAT——1001 害死人不偿命的(3n+1)猜想 (15)

    对给定的任一不超过1000的正整数n,简单地数一下,需要多少步(砍几下)才能得到n=1? 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值. 输出格式:输出从n计算到1需要的步数. 输入样例 ...

  7. PAT 1001 害死人不偿命的(3n+1)猜想

    1001 害死人不偿命的(3n+1)猜想 (15 分) 卡拉兹(Callatz)猜想: 对任何一个正整数 n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把 (3n+1) 砍掉一半.这样一直反复 ...

  8. PAT 1001. 害死人不偿命的(3n+1)猜想 (15)

    卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反复砍下去,最后一定在某一步得到 n=1.卡拉兹在1950年的世界 ...

  9. PAT 1001

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

  10. pat 1001 A+B Format

    题目链接:传送门 题目简述: 1. 给定两个整数值a,b: 2.范围-1000000 <= a, b <= 1000000: 3.按指定格式输出结果 例:-100000 9 输出: -99 ...

随机推荐

  1. [git]使用GPG签名你的commit

    概述 GPG是一种加密算法,现在github支持commit使用GPG加密,从而保证提交的commit在传输的过程中没有被篡改. 一.生成GPG密钥 什么是GPG:阮一峰的GPG教程 安装GPG:br ...

  2. UPW学习资料整理 .NET C# 转

    开发工具下载https://www.visualstudio.com/?Wt.mc_id=DX_MVP5000319 Windows 10 UWP开发视频1http://blogs.windows.c ...

  3. 最近一段时间开发客户端app的感悟

    关于android和cocos2d 凭着对大学时候写html+css的一点点的记忆,我还是认为android的布局xml文件还是参考了html+css,只是他更加臃肿!就想 android平台本身那样 ...

  4. SQL Server技术问题之存储过程与sql语句的优缺点

    优点: 1. 允许模块化程序设计.2.可维护性高,只需创建存储过程一次并将其存储在数据库中,以后即可在程序中调用该过程任意次.存储过程可独立于程序源代码而单独修改,而不需要更改.测试以及重新部署程序集 ...

  5. ASP.NET运行时详解 生命周期入口分析

    说起ASP.NET的生命周期,网上有很多的介绍.之前也看了些这方面的博客,但我感觉很多程序猿像我一样,看的时候似乎明白,一段时间过后又忘了.所以,最近Heavi花了一段时间研究ASP.NET的源代码, ...

  6. C#设计模式——生成器模式(Builder Pattern)

    一.概述在软件系统中,有时候面临着复杂的对象创建,该对象由一定算法构成的子对象组成,由于需求变化,这些子对象会经常变换,但组合在一起的算法却是稳定的.生成器模式可以处理这类对象的构建,它提供了一种封装 ...

  7. Fluent NHibernate and Spring.net

    http://blog.bennymichielsen.be/2009/01/04/using-fluent-nhibernate-in-spring-net/ http://comments.gma ...

  8. 由SimpleAyncTaskExecutor到ListenableFutureTask

    Spring AsyncExecutor观后感 导语 本来想看下spring关于Async&Sync TaskExecutor的主要内容,看着看着发现ListenableTaskExecuto ...

  9. redis 慢日志 slowlog

    1 slowlog是什么 redis的slowlog是redis用于记录记录慢查询执行时间的日志系统.由于slowlog只保存在内存中,因此slowlog的效率很高,完全不用担心会影响到redis的性 ...

  10. 你可以使用 play framework 做5件很爽的事情http://www.anool.net/?p=629

    1.绑定HTTP参数到JAVA方法里的参数. 使用PLAY可以很简单的从JAVA代码中检索HTTP参数.只要把方法参数申明成和HTTP参数相同既可. 比如,这个request: Http代码 /art ...