1001 A+B Format (20)
来源:互联网 发布:熟悉office办公软件 编辑:程序博客网 时间:2024/05/16 16:58
这题就是简单的输入A和B输出A+B
要求格式是包含逗号(三位一个逗号),就要求我们分离各位上的数然后逐位输出
有个小坑点是A+B=0的时候,加个判断就行了
#include <iostream>#include <cstdio>#include <stack>#include <cstring>#include <cstdlib>using namespace std;int main(){ int a,b,res; while (cin>>a>>b) { res=a+b; char d; int c[20]; memset(c,0,sizeof(c)); if (res<0) { cout<<'-'; res=-res; } if (res) { int i=0; while(res) { c[i]=res%10; res=res/10; i++; } for(int j=i-1;j>=0;j--) { if ((j+1)%3==0&&j+1!=i) cout<<','; cout<<c[j]; } } else { cout<<0; } cout<<endl; }}
阅读全文
0 0
- 1001 A+B Format (20)
- 1001 A+B Format (20)
- 1001 A+B Format
- 1001 A+B Format
- A+B Format (20)
- A+B Format (20)
- A+B Format (20)
- [PAT]1001 A+B Format (20)
- [PAT] 1001A+B Format (20)
- PAT 1001 A+B Format (20)
- PAT 1001 A+B Format
- pat 1001 A+B Format
- PAT 1001 A+B Format
- PAT 1001 A+B Format
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- PAT1001. A+B Format (20)
- 1001. A+B Format (20)
- 高频、射频、微波的区别
- vue-route+webpack部署单页路由项目,访问刷新出现404问题
- 【华为机试】句子逆序
- bzoj 2803: [Poi2012]Prefixuffix(双Hash)
- Ubuntu下安装搭建SS
- 1001 A+B Format (20)
- Hbase教程(四) Hbase数据库JavaAPI接口
- Mybatis传递多个参数的解决办法(三种)
- Acticle 23:有关浏览器中使用js跨域获取数据的描述
- Java IO 流总结
- c#冒泡排序 从大到小排序
- linux shell(一) helloWorld
- 常用IO流的使用方式
- A*算法