This commit is contained in:
Michal Utľák 2024-04-16 15:15:14 +02:00
parent b252054385
commit d805500070
2 changed files with 60 additions and 0 deletions

60
cv10/program.c Normal file
View File

@ -0,0 +1,60 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int pocet;
char pole[100][100];
int pocet_studentov = 0;
int ziadne_mena = 1;
while (fgets(pole[pocet_studentov], sizeof(pole[pocet_studentov]), stdin) != NULL) {
if (sscanf(pole[pocet_studentov], "%d", &pocet) == 1 && pocet > 0) {
ziadne_mena = 0;
break;
}
printf("Nespravny vstup\n");
return 1;
}
if (ziadne_mena) {
printf("Ziadne prihlasky\n");
return 1;
}
pocet_studentov++;
while (pocet_studentov < 100 && fgets(pole[pocet_studentov], sizeof(pole[pocet_studentov]), stdin) != NULL) {
pole[pocet_studentov][strcspn(pole[pocet_studentov], "\n")] = '\0';
pocet_studentov++;
}
if (pocet_studentov == 1) {
printf("Ziadne prihlasky\n");
return 1;
}
for (int i = 1; i < pocet_studentov - 1; i++) {
for (int j = i + 1; j < pocet_studentov; j++) {
if (strcmp(pole[i], pole[j]) > 0) {
char temp[100];
strcpy(temp, pole[i]);
strcpy(pole[i], pole[j]);
strcpy(pole[j], temp);
}
}
}
printf("Prijati studenti:\n");
for (int i = 1; i <= pocet && i < pocet_studentov; i++) {
printf("%s\n", pole[i]);
}
printf("Neprijati studenti:\n");
for (int i = pocet + 1; i < pocet_studentov; i++) {
printf("%s\n", pole[i]);
}
return 0;
}

BIN
cv10/program.exe Normal file

Binary file not shown.