pvjc21/du6/program.c

68 lines
1.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main(){
int freePlaces;
char inputs[100][50];
char* ptr;
int finalPosition;
int count = 0;
char temp[50];
for(int i = 0; fgets(inputs[i], 50, stdin) != NULL; i++){
if(i == 0){
freePlaces = (int) strtol(inputs[0], &ptr, 10);
if(freePlaces < 0 || !isdigit(freePlaces)){
printf("Nespravny vstup %d\n", freePlaces);
}
}
else if(i == 1 && !isalpha(inputs[i][0])){
printf("Ziadne prihlasky\n");
return 0;
}
else{
if(!strcmp(inputs[i], "")){
break;
}
}
finalPosition = 1;
}
//Код ниже избавляется от повторных заявок
for(int i = 0; i < finalPosition; i++){
for(int j = 0; j < finalPosition; j++){
if(!strcmp(inputs[i], inputs[j])){
strcpy(inputs[i], inputs[finalPosition]);
memset(inputs[finalPosition], '\0', 50);
}
}
}
//Этот код отвечает за сортировку заданных имён в списке зачисленных (а-я)
for(int i = 0; i < finalPosition; i++){
while(inputs[i][count] == inputs[i+1][count]){
count++;
}
if(inputs[i][count] > inputs[i+1][count]){
strcpy(temp, inputs[i]);
strcpy(inputs[i], inputs[i+1]);
strcpy(inputs[i+1], temp);
}
}
printf("Prijati studenti:\n");
for(int i = 1; i <= finalPosition; i++) {
printf ("%s", inputs[i]);
if(i == 5) break;
}
if(6 < finalPosition) printf("Neprijati studenti:\n");
for(int i = 6; i <= finalPosition; i++){
printf("%s", inputs[i]);
}
//free(ptr);
return 0;
}