2021-12-02 19:44:15 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdbool.h>
|
2021-12-02 23:01:02 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2021-12-02 19:44:15 +00:00
|
|
|
#define SIZE 100
|
|
|
|
|
|
|
|
bool jeKopa(int i, int inputNum[SIZE]);
|
2021-12-02 23:01:02 +00:00
|
|
|
void vypisovac(int vypis[SIZE], int input[SIZE], int size);
|
|
|
|
int ownPow(int base, int power);
|
|
|
|
int input(char string[100], int numbers[100]);
|
2021-12-02 19:44:15 +00:00
|
|
|
int main(){
|
|
|
|
char stringNum[100];
|
2021-12-02 23:01:02 +00:00
|
|
|
int inputNum[100] = {0}, i = 0;
|
|
|
|
fgets(stringNum,SIZE,stdin);
|
|
|
|
i = input(stringNum,inputNum) -1;
|
|
|
|
for (int j = 0; j < SIZE; j++){if(inputNum[j]<0-1){i++;}}
|
2021-12-02 19:44:15 +00:00
|
|
|
int vypis[100];
|
|
|
|
if(jeKopa(i,inputNum)){
|
|
|
|
printf("Je to taka kopa:");
|
2021-12-02 23:16:09 +00:00
|
|
|
int temp = 0, count = 0;
|
2021-12-02 19:44:15 +00:00
|
|
|
|
|
|
|
vypis[0] = 0;
|
|
|
|
for (int j = 0; j+1 < i; j++)
|
|
|
|
{
|
|
|
|
if (2*j+1 >= i)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
vypis[j+1] = 2*j+1;
|
2021-12-02 23:16:09 +00:00
|
|
|
vypis[i-(j)] = 2*j+2;
|
2021-12-02 19:44:15 +00:00
|
|
|
}
|
2021-12-02 23:16:09 +00:00
|
|
|
if (i%2!=0)
|
2021-12-02 19:44:15 +00:00
|
|
|
{
|
2021-12-02 23:16:09 +00:00
|
|
|
vypis[(i/2)+1] = i;
|
2021-12-02 19:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
printf("\n");
|
2021-12-02 23:16:09 +00:00
|
|
|
vypisovac(vypis,inputNum,i+1);
|
2021-12-02 19:44:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool jeKopa(int i, int inputNum[SIZE]){
|
|
|
|
for (int j = (i-1)/2; j >= 0; j--)
|
|
|
|
{
|
|
|
|
int l =2*i+1 , r = 2*i+2;
|
|
|
|
if (l>=i)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2021-12-02 23:16:09 +00:00
|
|
|
if (inputNum[j]>inputNum[l] || inputNum[j]>inputNum[r])
|
2021-12-02 19:44:15 +00:00
|
|
|
{
|
|
|
|
printf("Nieje kopa");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2021-12-02 23:01:02 +00:00
|
|
|
}
|
|
|
|
void vypisovac(int vypis[SIZE], int input[SIZE], int size){
|
|
|
|
int counter = 0, count = ownPow(2,0), space = 0, i = 0;
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
{
|
2021-12-02 23:16:09 +00:00
|
|
|
if (counter>=count && i<=(size/2))
|
2021-12-02 23:01:02 +00:00
|
|
|
{
|
|
|
|
count = ownPow(2,i)/2;
|
2021-12-02 23:42:58 +00:00
|
|
|
if (ownPow(2,i)%2){count++;}
|
2021-12-02 23:01:02 +00:00
|
|
|
counter = 0;
|
|
|
|
space++;
|
|
|
|
}
|
2021-12-02 23:02:51 +00:00
|
|
|
else if (counter>=count && i>(size/2) || vypis[i]<count-1)
|
2021-12-02 23:01:02 +00:00
|
|
|
{
|
2021-12-02 23:29:34 +00:00
|
|
|
if (input[vypis[i]]>input[vypis[i-1]])
|
|
|
|
{
|
|
|
|
count = ownPow(2,i)/2;
|
|
|
|
counter = 0;
|
|
|
|
}
|
|
|
|
else{
|
2021-12-02 23:01:02 +00:00
|
|
|
count = ownPow(2,size-i-1)/2;
|
|
|
|
counter = 0;
|
2021-12-03 00:00:33 +00:00
|
|
|
if (space > 1)
|
|
|
|
{
|
|
|
|
space--;
|
|
|
|
}
|
2021-12-02 23:29:34 +00:00
|
|
|
}
|
2021-12-02 23:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
counter++;
|
|
|
|
for (int k = 0; k < space; k++)
|
|
|
|
{
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
printf("%d\n",input[vypis[(int)i]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int ownPow(int base, int power){
|
|
|
|
int result = 0;
|
|
|
|
if (power>0)
|
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i<power; i++)
|
|
|
|
{
|
|
|
|
result = result * base;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
int input(char string[100], int numbers[100]){
|
|
|
|
int j = 0;
|
|
|
|
for (int i = 0; i < strlen(string); i++)
|
|
|
|
{
|
|
|
|
if (isdigit(string[i])){
|
|
|
|
numbers[j] = numbers[j]*10 + string[i]-'0';
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return j;
|
2021-12-02 19:44:15 +00:00
|
|
|
}
|