1001 A+B Format (20)(20 分)

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

code

#include <iostream>
int main(){
    int v1, v2, sum, x;
    int re[15];
    int i = 0;
    std::cin >> v1 >> v2;
    sum = v1 + v2;
    if(sum < 0) {
        std::cout << "-";
        sum = -sum;
    }
    do{
        x = sum % 10;
        sum = sum / 10;
        re[i] = x;
        i++;
    }while(sum != 0);
    std::cout << re[i-1];
    i--;
    while(i >= 1){
        if (i % 3 == 0) {
            std::cout << ',' << re[i-1];
        } else {
            std::cout << re[i-1];
        }
        i--;
    }
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • This time, you are supposed to find A+B where A and B are...
    AdmondGuo阅读 1,950评论 0 0
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,168评论 0 10
  • 闭包是前端开发中的一个重要概念,也是前端面试的必问问题之一。对于JavaScript初学者而言,闭包学习JavaS...
    玩毛线的毛线阅读 1,576评论 0 0
  • 我住过母亲的房 ———————————— 文 / 乐只君子 图 / 网络 我住过母亲的房 那是母亲温暖的子宫 房子...
    乐只君子_阅读 1,562评论 0 2
  • 就今天这里逢会,早早的起床,梳洗打扮准备去赶会,高高兴兴的出门,在会上溜达一圈,买了些东西回家,刚回到家,准...
    d7db246e7581阅读 1,351评论 2 3

友情链接更多精彩内容