日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

PAT (Advanced Level) Practise:1001. A+B Format

發(fā)布時間:2025/3/15 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PAT (Advanced Level) Practise:1001. A+B Format 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

【題目鏈接】

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

題意分析:

輸出(a+b)的結(jié)果,輸出格式需要使用逗號把數(shù)值分割。

提交代碼:

1 #include <stdio.h> 2 3 int main(void) 4 { 5 int out[10]; 6 int i, len, tmp; 7 int a, b, c; 8 9 scanf("%d %d", &a, &b); 10 11 c = a + b; 12 if(c < 0) 13 { 14 printf("-"); 15 c = -c; 16 } 17 18 len = 0; 19 do { 20 out[len] = c % 10; 21 c /= 10; 22 len++; 23 } while(c != 0); 24 25 for(i = 0; i < len; i++) 26 { 27 printf("%d", out[len-1-i]); 28 tmp = len - i - 1; 29 //if((len-i-1)%3 == 0 && (len-i) > 1) 30 if(tmp != 0 && tmp % 3 == 0) 31 printf(","); 32 } 33 34 return 0; 35 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/utank/p/4775653.html

總結(jié)

以上是生活随笔為你收集整理的PAT (Advanced Level) Practise:1001. A+B Format的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。