-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathN.cpp
More file actions
96 lines (48 loc) · 1.15 KB
/
Copy pathN.cpp
File metadata and controls
96 lines (48 loc) · 1.15 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include<stdio.h>
int check(int[],int,int);
int stop;
int main(){
int tar;
while (scanf("%d",&tar)!=EOF){
stop=0;
int i,k=-1, temp = tar, temp2=tar;
while (temp!=0){
temp /=10;
k++;
}
printf("k=%d\n",k);
int a[k+1];
for (i=0;i<k+1;i++)
{a[i]=temp2%10;
printf("%d\n",a[i]);
temp2/=10;
}
// printf("fine");
printf("%d",check (a, 0, k));
printf("st=%d",stop);
}
return 0;
}
int check (int a[], int s, int e){
if (stop==1) return 0;
else if (s+1==e) return a[s]+a[e];
else if (s==e) return a[s];
else {
int d = (s+e)/2;
int c1=check (a, s, d);
int c2=check (a, d+1, e);
int j1 = a[d-1]+a[d];
int j2 = a[d]+a[d+1];
int j3 = -1;
if (d+2<=e)
j3 = a[d+1]+a[d+2];
else
j3 = j2;
if (stop==0&&j1==j2&&j2==j3)
return j1;
else {
stop =1;
printf("sto=%d\n",stop);
return 0;}
}
}