PAT 1001
来源:互联网 发布:米多大数据引擎系统 编辑:程序博客网 时间:2024/05/22 14:06
原题目如下:
我的代码如下,题目很简单,考虑各种情况周全点就可以了
//输入任意两个整数,输出为标准格式如231000+322000=553,000 #include <iostream>#include <cmath>using namespace std;class add{private:int a,b;public:add(int,int);void out(void);};add::add(int temp1,int temp2){a=temp1;b=temp2;}void add::out(){int c=a+b;int sum=abs(c);int million=sum/1000000;int thousand=(sum-1000000*million)/1000;int hundred=sum-1000000*million-1000*thousand;if(c<0)cout<<'-';if(million){cout<<million<<',';if(thousand){if(thousand<100&&thousand>9)cout<<'0'<<thousand<<',';else if(thousand<10)cout<<"00"<<thousand<<',';elsecout<<thousand<<',';}elsecout<<"000,";if(hundred){if(hundred<100&&hundred>9)cout<<'0'<<hundred;else if(hundred<10)cout<<"00"<<hundred;elsecout<<hundred;}elsecout<<"000";}else{if(thousand){cout<<thousand<<',';if(hundred){if(hundred<100&&hundred>9)cout<<'0'<<hundred;else if(hundred<10)cout<<"00"<<hundred;elsecout<<hundred;}}elsecout<<hundred;}}int main(){int temp1,temp2;cin>>temp1>>temp2;add *p=new add(temp1,temp2);p->out();delete p;return 0;}
0 0
- pat 1001
- pat 1001
- PAT 1001
- PAT 1001
- PAT 1001
- PAT 1001
- PAT 1001
- PAT 1001
- PAT 1001
- PAT 1001
- PAT-1001
- PAT 1001
- PAT 1001
- PAT 1001
- PAT-1001
- PAT 1001
- PAT (BL) 1001
- PAT 1001-1010 题解
- 网络编程send()和recv()详解
- centos shell命令行只显示-bash-4.1#不显示用户和路径解决方法
- opencv中Mat与IplImage,CVMat类型之间转换
- 10.2 NSOperation/NSOperationQueue:提供了一些在GCD中不容易实现的特性,如:限制最大并发数量,操作之间的依赖关系.
- Android中创建文件夹和文件的操作
- PAT 1001
- 为什么程序员无法分清万圣节和圣诞节
- java基础——集合框架(二)
- 佳澜推荐美白补水的面膜
- Java堆内存富余却疯狂FullGc问题排查
- GRE数学复习备考指南
- 佳澜推荐美白补水面膜
- 全球公认的最健康作息时间表(2015就照个来)
- RHEL7安装谷歌chrome浏览器