Изменить '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>
struct LIS{
char name[100];
char fname[100];
char sname[100];
int num;
};
char keep(struct LIS*,int);
void sort(struct LIS*,int);
void print(struct LIS*,int,int);
@ -20,7 +19,7 @@ struct LIS list[100];
int places=0;
int k;
k=scanf("%d",&places);
if(k!=1 || places<=0){
if(k!=1 || places<0){
puts("Nespravny vstup");
}
else{
@ -33,16 +32,29 @@ else{
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);
char names[100];
for(;fgets(names,100,stdin);){
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;
}
void sort(struct LIS* list,int count){
@ -50,11 +62,11 @@ void sort(struct LIS* list,int count){
char *min;
int mini;
for(int i=0;i<count;i++){
min=list[i].sname;
min=list[i].fname;
mini=i;
for(int j=i+1;j<count;j++){
if(strcmp(min,list[j].sname)>0){
min=list[j].sname;
for(int j=i+1;j<=count;j++){
if(strcmp(min,list[j].fname)>0){
min=list[j].fname;
mini=j;
}
}
@ -64,22 +76,34 @@ void sort(struct LIS* list,int count){
}
}
void print(struct LIS *list,int count,int places){
int j=0;
int nado=places;
if(places>count){
nado=count;
}
if(count>0){
if(places>0){
puts("Prijati studenti:");
for(;j<nado;j++){
printf("%s %s\n",list[j].sname,list[j].fname);
printf("Prijati studenti:");
for(int i=0;i<=count;i++){
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");
for(int i=j;i<count;i++){
printf("%s %s\n",list[j].sname,list[j].fname);
}
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);
}
}
}
}
else{
puts("Ziadne prihlasky");
}
}
@ -87,3 +111,12 @@ void print(struct LIS *list,int count,int places){