您的位置:首页 > 其它

1001. A+B Format (20)

2015-02-06 23:40 337 查看
点击打开链接

#include <cstdio>
#define MAX 1000010
char pro[MAX];
char res[2*MAX];
int main(){
freopen("in.txt","r",stdin);
int a,b;
while(scanf("%d %d",&a,&b)!=EOF){
int c=a+b;
if(c!=0){
int flag=1;
if(c<0){
flag=0;
c=0-c;
}
int cnt=0;
while(c!=0){
pro[cnt++]=(c%10)+'0';
c/=10;
}
int cc=cnt;
int tmp=cnt;
tmp=cnt/3;
cc+=tmp;
if(cnt%3==0 && tmp!=0){
cc--;
}
res[cc--]='\0';
for(int i=0;i<cnt;i++){
if(i%3==0 && i!=0){
res[cc--]=',';
res[cc--]=pro[i];
}else{
res[cc--]=pro[i];
}

}
if(!flag){
printf("-");
}
puts(res);

}else{
printf("0\n");
}

}
return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: