diff --git a/a4/Makefile b/a4/Makefile new file mode 100644 index 0000000..f78f641 --- /dev/null +++ b/a4/Makefile @@ -0,0 +1,11 @@ +# variables +CC=gcc +CFLAGS=-std=c11 -Wall -Werror +LDLIBS=-lm +OUTPUT=$@ + +# targets +%: %.c + $(CC) $(CFLAGS) $@.c $(LDLIBS) -o $(OUTPUT) + + diff --git a/a4/program b/a4/program new file mode 100755 index 0000000..aac2250 Binary files /dev/null and b/a4/program differ diff --git a/a4/program.c b/a4/program.c new file mode 100644 index 0000000..615b865 --- /dev/null +++ b/a4/program.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include +#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; +} \ No newline at end of file