PAT (Advanced Level) 1001. A+B Format (20)
2016-05-15 19:55
387 查看
简单题。
#include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> using namespace std; int a,b,tot,cnt; int u[20]; char ans[100]; int main() { while(~scanf("%d%d",&a,&b)) { a=a+b; if(a==0) { printf("0\n"); continue; } int tmp=abs(a); tot=0,cnt=0; while(tmp) u[tot++]=tmp%10,tmp=tmp/10; for(int i=0; i<tot; i++) { ans[cnt++]=u[i]+'0'; if((i+1)%3==0&&tot-i!=1) ans[cnt++]=','; } if(a<0) ans[cnt++]='-'; for(int i=cnt-1; i>=0; i--) printf("%c",ans[i]); printf("\n"); } return 0; }
相关文章推荐
- PAT (Advanced Level) 1002. A+B for Polynomials (25)
- Spring MVC
- 解数独算法的研究
- RHEL7磁盘管理
- CentOS 7&RHEL 7重置root密码
- php显示数学公式
- JavaWeb项目的目录结构
- numpy的神奇广播函数
- Spring框架事务支持模型的优势
- PAT (Advanced Level) 1003. Emergency (25)
- linux安全---远程日志管理
- Intent传递对象的两种方法(Serializable,Parcelable)
- StreamUtils
- fork,你拿什么证明你的写时拷贝(COW)
- BLM业务领先模型
- POJ 2229 DP
- POJ 2229 DP
- Celery(二)-----------------使用Celery的第二步
- iOS framework 使用单元测试报错解决
- 使用配置文件为购物车提供一个商品放置数据库