Update 'du6/program.c'
This commit is contained in:
parent
f54ca48bb3
commit
f896c918c2
@ -1,63 +1,62 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#define MAXIMALNE_STUDENTOV 1000
|
#define MAX_STUDENTS 1000 // Maximum number of students
|
||||||
#define MENA 100
|
|
||||||
|
|
||||||
int main(){
|
int main() {
|
||||||
char spisok[MAXIMALNE_STUDENTOV][MENA]; //pole na ukladanie mien studentov
|
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
|
// Read the list of applications
|
||||||
puts("Nespravny vstup");
|
for (i = 0; i < MAX_STUDENTS; i++) {
|
||||||
return 1;
|
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
|
if (i == 0) {
|
||||||
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){
|
|
||||||
puts("Ziadne prihlasky");
|
puts("Ziadne prihlasky");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
num_studentov++;
|
// Sort the list of names in alphabetical order
|
||||||
|
for (int j = 0; j < i - 1; j++) {
|
||||||
if(num_studentov >= maximalne_studentov){ //po dosiahnuti maximalneho poctu studentov zastavte citanie
|
for (int k = j + 1; k < i; k++) {
|
||||||
break;
|
if (strcmp(names[j], names[k]) > 0) {
|
||||||
}
|
char temp[101];
|
||||||
}
|
strcpy(temp, names[j]);
|
||||||
|
strcpy(names[j], names[k]);
|
||||||
for(int a = 0; a < num_studentov; a++){ //zorad zoznam studentov podla abecedy
|
strcpy(names[k], temp);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
puts("Prijati studenti:");
|
// Print the list of accepted students
|
||||||
for(int a = 0; a < num_studentov && a < maximalne_studentov; a++){ //vytlacame zoznam prijatich studentov
|
puts("Prijati studenti:");
|
||||||
printf("%s\n", spisok[a]);
|
for (int j = 0; j < num_students && j < i; j++) {
|
||||||
}
|
printf("%s\n", names[j]);
|
||||||
|
|
||||||
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]);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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