Изменить 'du6/program.c'

This commit is contained in:
Pavlo Tverdyi 2020-04-16 13:16:09 +00:00
parent d9a292f9d9
commit b083926278

View File

@ -4,12 +4,11 @@
#include <ctype.h> #include <ctype.h>
struct LIS{ struct LIS{
char name[100];
char fname[100]; char fname[100];
char sname[100]; int num;
}; };
char keep(struct LIS*,int); char keep(struct LIS*,int);
void sort(struct LIS*,int); void sort(struct LIS*,int);
void print(struct LIS*,int,int); void print(struct LIS*,int,int);
@ -20,7 +19,7 @@ struct LIS list[100];
int places=0; int places=0;
int k; int k;
k=scanf("%d",&places); k=scanf("%d",&places);
if(k!=1 || places<=0){ if(k!=1 || places<0){
puts("Nespravny vstup"); puts("Nespravny vstup");
} }
else{ else{
@ -33,16 +32,29 @@ else{
char keep(struct LIS* list,int places){ char keep(struct LIS* list,int places){
int num=places;
int stop;
int count=0; int count=0;
char fn[100]; char names[100];
for(;stop!=EOF;count++,num--){ for(;fgets(names,100,stdin);){
stop=fscanf(stdin,"%s %s",list[count].sname,list[count].fname); if(sscanf(names,"%s %s",list[count].fname,list[count].name)==2){
if(places>=count){
list[count].num=0;
}
else{
list[count].num=1;
}
count++;
}
else if(sscanf(names,"%s",list[count].fname)==1){
if(places>=count){
list[count].num=2;
}
else{
list[count].num=3;
}
count++;
}
} }
count--;
return count; return count;
} }
void sort(struct LIS* list,int count){ void sort(struct LIS* list,int count){
@ -50,11 +62,11 @@ void sort(struct LIS* list,int count){
char *min; char *min;
int mini; int mini;
for(int i=0;i<count;i++){ for(int i=0;i<count;i++){
min=list[i].sname; min=list[i].fname;
mini=i; mini=i;
for(int j=i+1;j<count;j++){ for(int j=i+1;j<=count;j++){
if(strcmp(min,list[j].sname)>0){ if(strcmp(min,list[j].fname)>0){
min=list[j].sname; min=list[j].fname;
mini=j; mini=j;
} }
} }
@ -64,22 +76,34 @@ void sort(struct LIS* list,int count){
} }
} }
void print(struct LIS *list,int count,int places){ void print(struct LIS *list,int count,int places){
int j=0; if(count>0){
int nado=places;
if(places>count){
nado=count;
}
if(places>0){ if(places>0){
puts("Prijati studenti:"); printf("Prijati studenti:");
for(;j<nado;j++){ for(int i=0;i<=count;i++){
printf("%s %s\n",list[j].sname,list[j].fname); if(list[i].num==2){
printf("%s\n",list[i].fname);
}
if(list[i].num==0){
printf("%s %s\n",list[i].fname,list[i].name);
} }
} }
if(count-places>0) }
puts("Neprijati studenti:\n"); if(count-places>0){
for(int i=j;i<count;i++){ printf("Neprijati studenti:\n");
printf("%s %s\n",list[j].sname,list[j].fname); for(int i=0;i<=count;i++){
if(list[i].num==3){
printf("%s\n",list[i].fname);
}
if(list[i].num==1){
printf("%s %s\n",list[i].fname,list[i].name);
}
}
}
}
else{
puts("Ziadne prihlasky");
} }
} }
@ -87,3 +111,12 @@ void print(struct LIS *list,int count,int places){