(甲)PAT-1001

时间:2022-12-14 21:08:17

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");
     ;
 }