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--;
    }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • This time, you are supposed to find A+B where A and B are...
    AdmondGuo閱讀 307評(píng)論 0 0
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,854評(píng)論 0 10
  • 閉包是前端開(kāi)發(fā)中的一個(gè)重要概念,也是前端面試的必問(wèn)問(wèn)題之一。對(duì)于JavaScript初學(xué)者而言,閉包學(xué)習(xí)JavaS...
    玩毛線的毛線閱讀 253評(píng)論 0 0
  • 我住過(guò)母親的房 ———————————— 文 / 樂(lè)只君子 圖 / 網(wǎng)絡(luò) 我住過(guò)母親的房 那是母親溫暖的子宮 房子...
    樂(lè)只君子_閱讀 258評(píng)論 0 2
  • 就今天這里逢會(huì),早早的起床,梳洗打扮準(zhǔn)備去趕會(huì),高高興興的出門(mén),在會(huì)上溜達(dá)一圈,買(mǎi)了些東西回家,剛回到家,準(zhǔn)...
    d7db246e7581閱讀 197評(píng)論 2 3

友情鏈接更多精彩內(nèi)容