1001. A+B Format (20)
2015-09-04 09:31
357 查看
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.
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c;
intk=0,i,m=0;
chararray[16];
scanf("%d%d",&a,&b);
if(abs(a)>1000000||abs(b)>1000000)return 0;
c=a+b;
if(c<0)
{
printf("-");
c=abs(c);
}
if(c==0)printf("0");//容易给漏掉
while(c!=0)
{
array[k++]=c%10+48;
c/=10;
m++;
if(m%3==0&&c!=0)
array[k++]=',';
}
for(i=k-1;i>=0;i--)
{
printf("%c",array[i]);
}
printf("\n");
return 0;
}
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.
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c;
intk=0,i,m=0;
chararray[16];
scanf("%d%d",&a,&b);
if(abs(a)>1000000||abs(b)>1000000)return 0;
c=a+b;
if(c<0)
{
printf("-");
c=abs(c);
}
if(c==0)printf("0");//容易给漏掉
while(c!=0)
{
array[k++]=c%10+48;
c/=10;
m++;
if(m%3==0&&c!=0)
array[k++]=',';
}
for(i=k-1;i>=0;i--)
{
printf("%c",array[i]);
}
printf("\n");
return 0;
}
相关文章推荐
- Android AutoCompleteTextView自动提示输入
- CentOS系统启动流程-2015090401
- 15.命令模式
- JavaScript中的逻辑运算的返回值(逻辑与&&,逻辑或||,逻辑非!)
- 【翻译自mos文章】怎么正确的使用SQLNET.ALLOWED_LOGON_VERSION参数
- stl 容器
- java模板类以及数组的简单使用
- Docker新手入门:基本用法
- UILabel.text截取方式
- Docker新手入门:基本用法
- Bind 和 ScaffoldColumn[转]
- Linux文件系统管理―LVM
- Json 基本应用
- Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- 【JavaScript】实现计算日期相差天数
- 华为猴子吃桃子问题
- tableView 的 cell 的分割线样式
- android 开发录音那些事(录音权限授权及判断录音权限是否拒绝处理)
- django 1.8 官方文档翻译: 3-3-2 File对象
- 平衡二叉树