我是靠谱客的博主 火星上树叶,这篇文章主要介绍1001 1001. A+B Format (20),现在分享给大家,希望可以做个参考。

1001. A+B Format (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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
复制代码
1
-1000000 9
Sample Output

-999,991


//源代码

#include<cstdio>
#include<vector>
using namespace std;


vector<int> List;


int main(){
int a, b, sum;
int flag=0, digit;
int i;
scanf("%d %d", &a, &b);


sum = a + b;


if (sum == 0){
printf("%d", sum);
return 0;
}

if (sum < 0){
sum = -sum;
flag = 1;
}


while (sum>0){
digit = sum % 10;
List.push_back(digit);
sum = sum / 10;
}


if (flag == 1) printf("-");


for (i = List.size()-1; i>=0; i--){
printf("%d", List[i]);
if (i % 3 == 0 && i != 0) printf(",");
}
return 0;
}

最后

以上就是火星上树叶最近收集整理的关于1001 1001. A+B Format (20)的全部内容,更多相关1001内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(110)

评论列表共有 0 条评论

立即
投稿
返回
顶部