107 lines
1.9 KiB
C
107 lines
1.9 KiB
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
|
|
struct LIS{
|
|
char fname[100];
|
|
int num;
|
|
};
|
|
|
|
char keep(struct LIS*,int);
|
|
void sort(struct LIS*,int);
|
|
void print(struct LIS*,int,int);
|
|
|
|
int main(){
|
|
|
|
struct LIS list[100];
|
|
int places=0;
|
|
int k;
|
|
k=scanf("%d",&places);
|
|
if(k!=1 || places<0){
|
|
puts("Nespravny vstup");
|
|
}
|
|
else{
|
|
int count=keep(list,places);
|
|
sort(list,count);
|
|
print(list,count,places);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
char keep(struct LIS* list,int places){
|
|
int count=0;
|
|
char names[100];
|
|
for(;fgets(list[count].fname,100,stdin);){
|
|
if(list[count].fname[0]=='\n'){
|
|
list[count].num=-1;
|
|
// printf("skip");
|
|
}
|
|
if(list[count].fname[0]!='\n'){
|
|
list[count].num=0;
|
|
count++;
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
void sort(struct LIS* list,int count){
|
|
|
|
struct LIS ilusion;
|
|
char *min;
|
|
char *mickro;
|
|
int mini;
|
|
for(int i=0;i<=count-1;i++){
|
|
min=list[i].fname;
|
|
mini=i;
|
|
for(int j=i+1;j<=count;j++){
|
|
if(strcmp(min,list[j].fname)>0){
|
|
min=list[j].fname;
|
|
mini=j;
|
|
}
|
|
}
|
|
ilusion=list[i];
|
|
list[i]=list[mini];
|
|
list[mini]=ilusion;
|
|
}
|
|
}
|
|
|
|
void print(struct LIS *list,int count,int places){
|
|
|
|
if(count>0){
|
|
if(places>0){
|
|
int k=0;
|
|
printf("Prijati studenti:\n");
|
|
for(int i=0;k!=places+1;i++){
|
|
if(list[i].num==0){
|
|
fputs(list[i].fname,stdout);
|
|
k++;
|
|
}
|
|
}
|
|
}
|
|
if(count-places>0){
|
|
int k=0;
|
|
printf("Neprijati studenti:\n");
|
|
for(int i=places+1;i<count-1;i++){
|
|
if(list[i].num==0){
|
|
fputs(list[i].fname,stdout);
|
|
k++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|