国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

1001. A+B Format (20)

2019-11-11 03:17:00
字體:
供稿:網(wǎng)友

問題

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).InputEach 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.OutputFor 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 9Sample Output-999,991

題目地址:https://www.patest.cn/contests/pat-a-PRactise/1001

解答:

#include<stdio.h>
#define LEN 15void FormatPrint(const long int n);int main(){  int a, b;  scanf("%d %d", &a, &b);  FormatPrint(a + b);  return 0;}void FormatPrint(const long int n){  long int num;  if (n == 0) {    putchar('0');    return;  }  else if (n < 0)    num = -n;  else    num = n;  int i = 0;  int tag = 1;  char number[LEN] = { 0 };  while (num > 0) {    number[i++] = '0' + num % 10;    num /= 10;    if (tag % 3 == 0 && num != 0)      number[i++] = ',';    tag++;  }  if (n < 0)    putchar('-');  for (i = i - 1; i >= 0; i--)    putchar(number[i]);}


上一篇:Hdu 1234

下一篇:windows10安裝pip工具

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 崇仁县| 绥滨县| 高安市| 桃园县| 土默特左旗| 鄂州市| 汪清县| 汉川市| 双流县| 太仆寺旗| 滦南县| 黑山县| 汶上县| 合川市| 长宁县| 疏勒县| 自贡市| 峡江县| 浙江省| 宜春市| 华蓥市| 临潭县| 荥经县| 晋城| 白朗县| 新沂市| 赤水市| 芮城县| 枞阳县| 黎川县| 枣强县| 五寨县| 延川县| 达孜县| 田阳县| 宁安市| 垫江县| 德州市| 甘南县| 南丹县| 南溪县|