-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1001A.cpp
More file actions
44 lines (43 loc) · 894 Bytes
/
1001A.cpp
File metadata and controls
44 lines (43 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
int main()
{
int a, b, total=0;
int result[10];
int index=0;
int flag=0;//ÅжÏÊÇ·ñΪ¸ºÊý£¬ÊÇΪ1
for(int i=0;i<10;i++)
result[i]=0;
scanf("%d%d",&a, &b);
total=a+b;
if(total<0){
flag=1;
total=-total;
}
if(total==0){
printf("%d",total);
}
while(total){
result[index]=total%10;
total=total/10;
index++;
}
int first=(index)%3;
if(flag==1)
printf("-");
for(int i=0;i<first;i++){
printf("%d",result[index-i-1]);
}
if((index!=first)&&(first!=0)){
printf(",");
}
int num=0;
for(int i=first;i<index;i++){
printf("%d",result[index-i-1]);
num++;
while((num==3)&&(i!=index-1)){
printf(",");
num=0;
}
}
return 0;
}