This commit is contained in:
Peter Petrek 2021-12-02 20:44:15 +01:00
parent a3fc14b073
commit a7dcfdeb81
3 changed files with 88 additions and 0 deletions

11
a4/Makefile Normal file
View File

@ -0,0 +1,11 @@
# variables
CC=gcc
CFLAGS=-std=c11 -Wall -Werror
LDLIBS=-lm
OUTPUT=$@
# targets
%: %.c
$(CC) $(CFLAGS) $@.c $(LDLIBS) -o $(OUTPUT)

BIN
a4/program Executable file

Binary file not shown.

77
a4/program.c Normal file
View File

@ -0,0 +1,77 @@
#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;
}