57 lines
1.0 KiB
C
57 lines
1.0 KiB
C
|
#include <stdio.h>
|
||
|
|
||
|
int check(int i, int size, int array[])
|
||
|
{
|
||
|
if (i >= size)
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
else if (array[i] < array[(i - 1) / 2])
|
||
|
{
|
||
|
return 1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return check(i * 2 + 1, size, array) + check(i * 2 + 2, size, array);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int spaces = 0;
|
||
|
void print(int i, int size, int array[])
|
||
|
{
|
||
|
if(i >= size)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
for(int j = 0; j < spaces; j++)
|
||
|
{
|
||
|
printf(" ");
|
||
|
}
|
||
|
printf("%d\n", array[i]);
|
||
|
spaces = spaces + 1;
|
||
|
print(i * 2 + 1, size, array);
|
||
|
print(i * 2 + 2, size, array);
|
||
|
spaces = spaces - 1;
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
int array[1000];
|
||
|
int size = 0;
|
||
|
while(scanf("%d", &array[size]) != EOF)
|
||
|
{
|
||
|
size++;
|
||
|
}
|
||
|
int result = check(0, size, array);
|
||
|
if (result == 0)
|
||
|
{
|
||
|
spaces = 0;
|
||
|
printf("Je to taka kopa:\n");
|
||
|
print(0, size, array);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("Nie je kopa.\n");
|
||
|
return 0;
|
||
|
}
|
||
|
}
|