104 lines
1.8 KiB
C
104 lines
1.8 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;
|
|
}
|
|
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;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){
|
|
int i=0;
|
|
if(places>0){
|
|
int k=1;
|
|
for(int i=0;k!=places+1;i++){
|
|
if(list[i].num==0){
|
|
fputs(list[i].fname,stdout);
|
|
printf("%d ",k);
|
|
k++;
|
|
}
|
|
}
|
|
}
|
|
if(count-places>0){
|
|
printf("Neprijati studenti:\n");
|
|
for(i;i<30;i++){
|
|
if(list[i].num==0){
|
|
fputs(list[i].fname,stdout);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|