Update 'du6/program.c'
This commit is contained in:
parent
f54ca48bb3
commit
f896c918c2
@ -1,63 +1,62 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MAXIMALNE_STUDENTOV 1000
|
||||
#define MENA 100
|
||||
#define MAX_STUDENTS 1000 // Maximum number of students
|
||||
|
||||
int main(){
|
||||
char spisok[MAXIMALNE_STUDENTOV][MENA]; //pole na ukladanie mien studentov
|
||||
int main() {
|
||||
int num_students, i;
|
||||
char names[MAX_STUDENTS][101];
|
||||
char name[101];
|
||||
|
||||
int maximalne_studentov, num_studentov = 0;
|
||||
// Read the maximum number of students
|
||||
if (scanf("%d", &num_students) != 1) {
|
||||
puts("Nespravny vstup");
|
||||
return 1;
|
||||
}
|
||||
if (num_students <= 0 || num_students > MAX_STUDENTS) {
|
||||
puts("Nespravny vstup");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(scanf("%d", &maximalne_studentov) != 1){ //precitane si maximalny pocet prijatych studentov
|
||||
puts("Nespravny vstup");
|
||||
return 1;
|
||||
}
|
||||
// Read the list of applications
|
||||
for (i = 0; i < MAX_STUDENTS; i++) {
|
||||
if (fgets(name, 101, stdin) == NULL || strcmp(name, "\n") == 0) {
|
||||
break; // Stop reading when encountering an empty line or EOF
|
||||
}
|
||||
name[strcspn(name, "\n")] = '\0'; // Remove the trailing newline character
|
||||
strcpy(names[i], name); // Add the name to the list
|
||||
}
|
||||
|
||||
while(fgets(spisok[num_studentov], MENA, stdin)){ //precitajte si zoznam studentskych prihlasok
|
||||
spisok[num_studentov][strcspn(spisok[num_studentov], "\n")] = '\0'; //odstranie koncovoho znaka noveho riadku
|
||||
|
||||
|
||||
if(spisok[num_studentov][0] == '\0'){ //zastavnie citanie ak najdeni prazdny riadok alebo koniec suboru
|
||||
break;
|
||||
}
|
||||
|
||||
for(int a = 0; a < num_studentov; a++){ //skontrolujem duplicitne mena
|
||||
if(strcmp(spisok[a], spisok[num_studentov]) == 0){
|
||||
if (i == 0) {
|
||||
puts("Ziadne prihlasky");
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
num_studentov++;
|
||||
|
||||
if(num_studentov >= maximalne_studentov){ //po dosiahnuti maximalneho poctu studentov zastavte citanie
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(int a = 0; a < num_studentov; a++){ //zorad zoznam studentov podla abecedy
|
||||
for(int b = a +1; b < num_studentov; b++){
|
||||
if(strcmp(spisok[a], spisok[b]) > 0){
|
||||
char p[MENA];
|
||||
strcpy(p, spisok[a]);
|
||||
strcpy(spisok[a], spisok[b]);
|
||||
strcpy(spisok[b], p);
|
||||
// Sort the list of names in alphabetical order
|
||||
for (int j = 0; j < i - 1; j++) {
|
||||
for (int k = j + 1; k < i; k++) {
|
||||
if (strcmp(names[j], names[k]) > 0) {
|
||||
char temp[101];
|
||||
strcpy(temp, names[j]);
|
||||
strcpy(names[j], names[k]);
|
||||
strcpy(names[k], temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
puts("Prijati studenti:");
|
||||
for(int a = 0; a < num_studentov && a < maximalne_studentov; a++){ //vytlacame zoznam prijatich studentov
|
||||
printf("%s\n", spisok[a]);
|
||||
}
|
||||
|
||||
if(num_studentov > maximalne_studentov){ //vytlacame zoznam odmietnutych studentov
|
||||
puts("Neprijati studenti:");
|
||||
for(int a = maximalne_studentov; a < num_studentov; a++){
|
||||
printf("%s\n", spisok[a]);
|
||||
// Print the list of accepted students
|
||||
puts("Prijati studenti:");
|
||||
for (int j = 0; j < num_students && j < i; j++) {
|
||||
printf("%s\n", names[j]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
// Print the list of rejected students
|
||||
if (i > num_students) {
|
||||
puts("Neprijati studenti:");
|
||||
for (int j = num_students; j < i; j++) {
|
||||
printf("%s\n", names[j]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user