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. 【转】SAPI中的IspeechRecoContext(接口)

    IspeechRecoContext自动化接口定义一个识别上下文. 什么是一个识别上下文? 一个识别上下文就是应用程序和SAPI共同作用来实现语音识别的最主要方法.它就是用来允许应用程序来开始.停止识 ...

  2. IOS开发UI基础UISegment属性

    UISegment属性 1.segmentedControlStyle设置segment的显示样式.typedef NS_ENUM(NSInteger, UISegmentedControlStyle ...

  3. [ASP.NET]谈谈REST与ASP.NET Web API

    13天的假期结束,赶紧回来充电了 本节目录 Web API简介 自我寄宿 IIS寄宿 调用Web API Web API原理 Web API简介 REST REST是“REpresentational ...

  4. istView的项移除

    如标题所言,是做删除ListView绑定项的功能的:鉴于这个功能当时确实花费了很多时间,并且网上也找不到删除所需的案例,所以,我就做了一份案例,仅供各位前辈和同行进行参考,如有不当之处,还望指点,我将 ...

  5. jquery实现智能表单

    现在很多网站的注册模块都可以实现即时检查格式是否正确,这样极大的增强了用户体验,对开发非常有利. 下面的代码是利用jquery实现了对一个表单字段格式的即时检查(包括字段长度.邮箱格式),同时在提交时 ...

  6. HTML5 Wijmo:控制 Wijmo Grid 插件的编辑模式

    Wijmo jQuery 插件经常应用于在财务类网站中创建平滑和良好用户体验的交互表格.WijGrid 插件用于显示.排序.分组和编辑数据.今天我们来分享下如何控件WijGrid插件的编辑模式. 在本 ...

  7. 外表cms,内在wiki的系统anwiki

    比较完整面向对象的语法格式,     外表cms,内在wiki的系统   http://enanocms.org/features   比较老,php4的语法

  8. 小白学Linux(五)--VI/VIM编辑器

    我们操作文件,终究离不开编辑文件,对文件内容的编辑,Linux系统下,我们通常使用VI/VIM来编辑文件.VI是每个Linux都会自带的文本编辑器,VIM是VI的增强版,可能有些发行版本没有自带,可以 ...

  9. 平衡二叉树---Shaolin

    Description Shaolin temple is very famous for its Kongfu monks.A lot of young men go to Shaolin temp ...

  10. 泛函编程(20)-泛函库设计-Further Into Parallelism

    上两节我们建了一个并行运算组件库,实现了一些基本的并行运算功能.到现在这个阶段,编写并行运算函数已经可以和数学代数解题相近了:我们了解了问题需求,然后从类型匹配入手逐步产生题解.下面我们再多做几个练习 ...