pvjc20/du6/program.c

84 lines
1.5 KiB
C

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
struct LIS{
char fname[100];
char sname[100];
};
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 num=places;
int stop;
int count=0;
char fn[100];
for(;stop!=EOF;count++,num--){
stop=fscanf(stdin,"%s %s",list[count].sname,list[count].fname);
}
count=-2;
return count;
}
void sort(struct LIS* list,int count){
struct LIS ilusion;
char *min;
int mini;
for(int i=0;i<count;i++){
min=list[i].sname;
mini=i;
for(int j=i+1;j<count;j++){
if(strcmp(min,list[j].sname)>0){
min=list[j].sname;
mini=j;
}
}
ilusion=list[i];
list[i]=list[mini];
list[mini]=ilusion;
}
}
void print(struct LIS *list,int count,int places){
int j=0;
if(places>0){
puts("Prijati studenti:\n");
for(;j<places;j++){
printf("%s %s\n",list[j].sname,list[j].fname);
}
}
puts("Neprijati studenti:\n");
for(int i=j;i<count;i++){
printf("%s %s\n",list[j].sname,list[j].fname);
}
}