usaa21/a4/program.c
Peter Petrek ab43e8c0b9 2nd
2021-12-02 20:57:18 +01:00

85 lines
1.7 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");
int count = 0;
for (int j = 0; j < i-1; j++)
{
if (j<=(i)/2)
{
for (int k = 0; k < count; k++)
{
printf(" ");
}
count++;
}
printf("%d\n",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;
}