-
Notifications
You must be signed in to change notification settings - Fork 1
/
zad7_ms.c
51 lines (44 loc) · 967 Bytes
/
zad7_ms.c
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
#include <stdio.h>
#include <stdlib.h>
/// @brief
/// @param n
/// @param t
/// @return array of indexes ending seeked divisions of the set t. -1 means the end of array
int *podziel(int n, int t[])
{
int max;
int count = 0;
int *indexes = (int *)malloc((size_t)n * sizeof(int));
for (int i = 0; i < n; i++)
{
if (t[i] > max)
{
max = t[i];
}
if (max == i)
{
// insert
indexes[count++] = i;
max = -1;
}
}
indexes[count] = -1;
return indexes;
}
int main()
{
int n;
if(!scanf("%d", &n)) printf("wrong input");
int *t = (int *)malloc((unsigned)n * sizeof(int));
for (int i = 0; i < n; i++)
{
if(!scanf("%d", &t[i])) printf("wrong input");
}
int *indexes = podziel(n, t);
for (int i = 0; i < n; i++)
{
if (indexes[i] == -1)
break;
printf("%d\n", indexes[i]);
}
}