usaa21/a4/program.c
Peter Petrek a7dcfdeb81 first
2021-12-02 20:44:15 +01:00

77 lines
1.5 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#define SIZE 100
bool jeKopa(int i, int inputNum[SIZE]);
int main(){
char stringNum[100];
int inputNum[100], i = 0;
while (1)
{
//scanf("%s",&stringNum);
fgets(stringNum,SIZE,stdin);
stringNum[strlen(stringNum)-1] = '\0';
if (!isdigit(stringNum[0]))
{
break;
}
inputNum[i] = atoi(stringNum);
i++;
}
for (int j = (i-1)/2; j >= 0; j--)
{
}
int vypis[100];
if(jeKopa(i,inputNum)){
printf("Je to taka kopa:");
//int temp = 0, count = 0;
vypis[0] = 0;
for (int j = 0; j+1 < i; j++)
{
if (2*j+1 >= i)
{
break;
}
vypis[j+1] = 2*j+1;
vypis[i-(j+1)] = 2*j+2;
}
if (i%2==0)
{
vypis[i/2] = inputNum[i-1];
}
}
printf("\n");
for (int j = 0; j < i; j++)
{
printf("%d, ",inputNum[vypis[j]]);
}
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;
}
if (inputNum[j]>inputNum[l] || inputNum[j]>inputNum[r])
{
printf("Nieje kopa");
return 0;
}
}
return 1;
}