68 lines
1.9 KiB
C
68 lines
1.9 KiB
C
#include <stdio.h>
|
|
#include <ctype.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int main() {
|
|
int freePlaces;
|
|
char inputs[100][50];
|
|
for(int i = 0; i < 100; i++)
|
|
memset(inputs[i], '\0', 50);
|
|
char* ptr;
|
|
int finalPosition;
|
|
int count = 0;
|
|
|
|
for(int i = 0; fgets(inputs[i], 50, stdin) != NULL; i++){
|
|
if(i == 0){
|
|
inputs[i][strlen(inputs[i])-1] = '\0';
|
|
for(int j = 0; j < strlen(inputs[i]); j++){
|
|
if(!isdigit(inputs[i][j])){
|
|
printf("Nespravny vstup\n");
|
|
return 0;
|
|
}
|
|
}
|
|
freePlaces = (int)strtol(inputs[i], &ptr, 10);
|
|
if(freePlaces <= 0){
|
|
printf("Nespravny vstup\n");
|
|
return 0;
|
|
}
|
|
}
|
|
else if(i == 1 && !isalpha(inputs[i][0])){
|
|
printf("Ziadne prihlasky\n");
|
|
return 0;
|
|
}
|
|
else{
|
|
if(!strcmp(inputs[i], "") || inputs[i][0] == '\n')
|
|
break;
|
|
}
|
|
finalPosition = i;
|
|
}
|
|
|
|
//The code below removes repeating applicants
|
|
for(int i = 0; i <= finalPosition; i++){
|
|
for(int j = 0; j <= finalPosition; j++){
|
|
if(!strcmp(inputs[i], inputs[j]) && i != j) {
|
|
strcpy(inputs[i], inputs[finalPosition]);
|
|
memset(inputs[finalPosition--], '\0', 50);
|
|
}
|
|
}
|
|
}
|
|
|
|
//The code below orders the applicants by name (a-z)
|
|
qsort(inputs, finalPosition+1, 50*sizeof(char), strcmp);
|
|
|
|
printf("Prijati studenti:\n");
|
|
for(int i = 1; i <= freePlaces; i++){
|
|
if(inputs[i][0] != '\n' && inputs[i][0] != '\0'){
|
|
printf("%s", inputs[i]);
|
|
}
|
|
}
|
|
if(freePlaces+1 < finalPosition) printf("Neprijati studenti:\n");
|
|
for(int i = freePlaces+1; i <= finalPosition; i++){
|
|
if(isalpha(inputs[i][0])){
|
|
printf("%s", inputs[i]);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
} |