PAT1001.A+B Format
来源:互联网 发布:正规淘宝兼职平台 编辑:程序博客网 时间:2024/05/19 11:35
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
ps:与其他网站的第一题确实有不小的区别。需要小小地注意下a+b=0的情况。
#include<stdio.h>#include<string.h>
#define N 100int str[N];
int main(){ int a,b; scanf("%d%d",&a,&b); a+=b; if( !a ) { printf("0\n"); return 0; } if( a<0 ) { a=-a; putchar('-'); } int pos=0; while( a ) { str[pos++]=a%10; a/=10; } for(int i=pos-1;i>=0;i--) { printf("%d",str[i]); if( !(i%3) && i ) putchar(','); } puts("");
return 0;}
- PAT1001.A+B Format
- PAT1001. A+B Format
- PAT1001. A+B Format .
- PAT1001. A+B Format
- PAT1001-A+B Format
- PAT1001 A+B format
- PAT1001 A+B Format
- PAT1001. A+B Format (20)
- PAT1001. A+B Format (20)
- PAT1001. A+B Format (20)
- PAT1001 A+B Format (20)
- PAT1001---A+B Formatb
- 1001. A+B Format
- A+B Format (20)
- PAT_1001: A+B Format
- 1001.A+B Format
- 1001. A+B Format
- 1001. A+B Format
- 网站运营中活动组织的三项注意
- cygwin使用
- C++开源库
- 伪类和类
- 基于互斥对象的线程同步
- PAT1001.A+B Format
- 返回easyui/extjs中datagrid使用的json格式
- Expect学习笔记
- Ubuntu 12.04 root用户登录设置
- 配置IIS服务器(各种系统上)
- ACM之游泳比赛
- 工厂模式—简单工厂模式(Simple Factory Pattern)
- jsp js 函数 传参 只接受<%=request.getAttribute("name")%> 形式
- 开源类库