A+B Format (20)
来源:互联网 发布:2016年上证指数数据 编辑:程序博客网 时间:2024/04/25 14:28
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>using namespace std;int main(){int N,M;while(scanf("%d%d",&N,&M)!=EOF){ int total=N+M; bool isminus=false; if(total<0) { total=(-1)*total; isminus=true; } int parts[5]; int len=0; if(total<1000) { parts[len]=total; total=0; len++; } while(total!=0) { parts[len]=total%1000; total=total/1000; len++; } len--; if(isminus) cout<<"-"; if(len!=0) cout<<parts[len]<<","; else cout<<parts[len]<<endl; for(int i=len-1;i>0;i--) { if(parts[i]<10) cout<<"00"<<parts[i]<<","; else if(parts[i]<100) cout<<"0"<<parts[i]<<","; else cout<<parts[i]<<","; } if(len!=0) { if(parts[0]<10) cout<<"00"<<parts[0]<<endl; else if(parts[0]<100) cout<<"0"<<parts[0]<<endl; else cout<<parts[0]<<endl; } } return 0;}
- A+B Format (20)
- A+B Format (20)
- A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- PAT1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 图片,音频,视频文件的上传 以及图片缩略图的制作,音频文件时长的获取以及 视频文件缩略图的获取
- 进程和线程的区别
- 体内湿气不排出,永远睡不饱
- 从linux内核启动说起(二)
- 红黑树插入的栈实现
- A+B Format (20)
- 常用的Python命令
- 获取android源码时repo的错误
- 方法签名
- VS2010 Qt配置
- Svnsync如何实现同步,以及出现的各种问题?
- C#中多线程的参数传递
- 用c写的一个栈的链表实现
- hibernate主键生成策略generator