-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10035.c
More file actions
82 lines (72 loc) · 1.25 KB
/
10035.c
File metadata and controls
82 lines (72 loc) · 1.25 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdio.h>
int main(int argc, char const *argv[])
{
int a,b;
/*int a[10000],b[10000];
int ki;//偵測有幾組測資
for (int k = 0; ; ++k)
{
scanf("%d %d",&a[k],&b[k]);
if(a[k]==0&&b[k]==0){
ki=k; //將測資次數存進ki
break;
}
}*/
//printf("%d\n",ki );
while(1){
scanf("%d %d",&a,&b);
if(a==0&&b==0) break;
int aa[10]={0},ba[10]={0},ac=0,bc=0;
for (int i = 0; ; ++i) //把a[i]輸入陣列
{
if(a>=1){
aa[i]=a%10;
a/=10;
ac++;
//printf("%dac\n",a );
}
else
break;
}
//printf("%dac\n",ac );
for (int i = 0; ; ++i) //把b[i]輸入陣列
{
if(b>=1){
ba[i]=b%10;
b/=10;
bc++;
}
else
break;
}
//printf("%dbc\n",bc );
int fc=0; //用來計數有沒有進位
int count=ac<bc?bc:ac;
for (int i = 0; i <count; ++i)
{
if(aa[i]+ba[i]>=10){
aa[i+1]++;
fc++;
//printf("%di\n",i );
}
}
//printf("%dans\n",fc );
if(fc==0){
printf("No carry operation.\n");
}
else if(fc==1){
printf("1 carry operation.\n");
}
else
printf("%d carry operations.\n",fc);
/*int temp;
for (int i = 0; i < ac/2; ++i) //顛倒數字
{
temp=aa[i];
aa[i]=aa[ac-i-1];
aa[ac-i-1]=temp;
}*/
}
//printf("\n");
return 0;
}