http://pat.zju.edu.cn/contests/pat-practise/1001
来源:互联网 发布:java.io jar包 编辑:程序博客网 时间:2024/04/30 21:02
1001. A+B Format (20)
时间限制
400 ms
内存限制
32000 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-1000000 9Sample Output
-999,991
- #include<iostream>
- #include<cstdio>
- #include<cstdlib>
- #include<algorithm>
- #include<memory.h>
- #include<string>
- using namespace std;
- int main(){
- //freopen("in.txt", "r", stdin);
- int a, b;
- char s[10];
- int ans;
- while(cin>>a>>b){
- ans = a+b;
- if(ans<0){
- printf("-");
- ans = -ans;
- }
- int k = 0;
- if(ans==0)
- s[k++]='0';
- while(ans!=0){
- s[k++] = ans%10 + '0';
- ans /= 10;
- }
- s[k] = '\0';
- int len = strlen(s);
- for(int i=len-1;i>=0;i--){
- printf("%c", s[i]);
- if(i%3==0 && i!=0)
- printf(",");
- }
- printf("\n");
- }
- //fclose(stdin);
- }
- http://pat.zju.edu.cn/contests/pat-practise/1001
- http://pat.zju.edu.cn/contests/pat-practise/1030
- http://pat.zju.edu.cn/contests/pat-practise/1034
- http://pat.zju.edu.cn/contests/pat-practise/1016
- http://pat.zju.edu.cn/contests/pat-practise/1032
- http://pat.zju.edu.cn/contests/pat-practise/1037
- http://pat.zju.edu.cn/contests/pat-practise/1021
- http://pat.zju.edu.cn/contests/pat-practise/1040
- http://pat.zju.edu.cn/contests/pat-practise/1038
- http://pat.zju.edu.cn/contests/pat-practise/1025
- http://pat.zju.edu.cn/contests/pat-practise/1023
- http://pat.zju.edu.cn/contests/pat-practise/1029
- http://pat.zju.edu.cn/contests/pat-practise/1035
- http://pat.zju.edu.cn/contests/pat-practise/1024
- http://pat.zju.edu.cn/contests/pat-practise/1031
- http://pat.zju.edu.cn/contests/pat-practise/1028
- http://pat.zju.edu.cn/contests/pat-practise/1020
- http://pat.zju.edu.cn/contests/pat-practise/1015
- 数据结构——KMP算法的实现
- 28个Unix/Linux的命令行神器
- http://pat.zju.edu.cn/contests/pat-practise/1003
- pragma comment的使用
- setAttribute和setParameter方法的区别
- http://pat.zju.edu.cn/contests/pat-practise/1001
- 纽约时报称莫言获诺贝尔奖打破欧洲作家垄断-莫言-诺贝尔文学奖-村上春树
- python的json操作
- 【最小生成树】安慰员工
- Wormholes poj3259
- 流行Linux和Windows脚本语言列表
- SQL LIKE语句多条件贪婪加权匹配算法(改进版)
- 莫言称获奖是文学的胜利 批判社会黑暗凌厉严肃-莫言-诺贝尔文学奖-出国
- 纵观jBPM:从jBPM3到jBPM5以及Activiti5