Изменить '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,15 +4,14 @@
#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);
int main(){ int main(){
@ -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>0){
if(places>count){ printf("Prijati studenti:");
nado=count; for(int i=0;i<=count;i++){
} if(list[i].num==2){
if(places>0){ printf("%s\n",list[i].fname);
puts("Prijati studenti:"); }
for(;j<nado;j++){ if(list[i].num==0){
printf("%s %s\n",list[j].sname,list[j].fname); printf("%s %s\n",list[i].fname,list[i].name);
}
}
}
if(count-places>0){
printf("Neprijati studenti:\n");
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);
}
}
} }
} }
if(count-places>0) else{
puts("Neprijati studenti:\n"); puts("Ziadne prihlasky");
for(int i=j;i<count;i++){
printf("%s %s\n",list[j].sname,list[j].fname);
} }
} }
@ -87,3 +111,12 @@ void print(struct LIS *list,int count,int places){