Newer
Older
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
#include <stdio.h>
#define MARK -1
#define LEN(x) (sizeof(x) / sizeof(*x))
void copy(int to[], int from[], int n, int *ret) {
int i = 0;
while (from[i] != MARK && i < n - 1) {
to[i] = from[i];
++i;
}
to[i] = MARK;
*ret = from[i] == MARK ? 1 : -1;
}
void cmp(int a1[], int a2[], int *ret) {
int i = 0;
while (a1[i] != MARK && a2[i] != MARK && a1[i] == a2[i]) { ++i; }
*ret = a1[i] == a2[i] ? 1 : -1;
}
int count_greater(int a1[], int a2[]) {
int i = 0;
int ret = 0;
while (a1[i] != MARK && a2[i] != MARK) {
if (a1[i] > a2[i]) { ++ret; }
++i;
}
while (a2[i] != MARK) {
++ret;
++i;
}
return ret;
}
int copy_even_positions(int to[], int from[], int n) {
int i = 0;
while (from[i * 2] && from[(i * 2) + 1] != MARK && i < n - 1) {
to[i] = from[i * 2];
++i;
}
to[i] = MARK;
return i;
}
int sum(int a1[], int a2[], int n, int sum[]) {
int i = 0;
while (a1[i] != MARK && a2[i] != MARK && i < n - 1) {
sum[i] = a1[i] + a2[i];
++i;
}
while (a1[i] != MARK && i < n - 1) {
sum[i] = a1[i];
++i;
}
while (a2[i] != MARK && i < n - 1) {
sum[i] = a2[i];
++i;
}
sum[i] = MARK;
return a1[i] == MARK || a2[i] == MARK ? 1 : -1;
}