pvjc20/du6/program.c

114 lines
2.1 KiB
C
Raw Normal View History

2020-04-13 21:49:38 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
2020-04-16 00:16:00 +00:00
struct LIS{
char fname[100];
2020-04-16 13:16:09 +00:00
int num;
2020-04-16 00:16:00 +00:00
};
2020-04-16 13:16:09 +00:00
2020-04-16 00:16:00 +00:00
char keep(struct LIS*,int);
void sort(struct LIS*,int);
2020-04-16 13:16:09 +00:00
void print(struct LIS*,int,int);
2020-04-16 20:40:19 +00:00
void AAAAA(struct LIS*, int,int);
2020-04-13 21:49:38 +00:00
2020-04-16 00:16:00 +00:00
int main(){
struct LIS list[100];
int places=0;
int k;
k=scanf("%d",&places);
2020-04-16 13:16:09 +00:00
if(k!=1 || places<0){
2020-04-16 00:16:00 +00:00
puts("Nespravny vstup");
}
else{
int count=keep(list,places);
sort(list,count);
2020-04-16 20:40:19 +00:00
AAAAA(list,count,places);
2020-04-16 00:16:00 +00:00
print(list,count,places);
}
2020-04-13 21:49:38 +00:00
return 0;
}
2020-04-16 00:16:00 +00:00
char keep(struct LIS* list,int places){
int count=0;
2020-04-16 13:16:09 +00:00
char names[100];
2020-04-16 19:22:15 +00:00
for(;fgets(list[count].fname,100,stdin);){
2020-04-16 19:09:03 +00:00
if(list[count].fname[0]=='\n'){
list[count].num=-1;
2020-04-16 13:16:09 +00:00
}
2020-04-16 19:09:03 +00:00
if(list[count].fname[0]!='\n'){
2020-04-16 19:22:15 +00:00
list[count].num=0;
count++;
2020-04-16 19:09:03 +00:00
}
2020-04-16 00:16:00 +00:00
}
return count;
}
void sort(struct LIS* list,int count){
2020-04-16 19:09:03 +00:00
struct LIS ilusion;
char *min;
char *mickro;
int mini;
2020-04-16 19:48:09 +00:00
for(int i=0;i<count;i++){
2020-04-16 13:16:09 +00:00
min=list[i].fname;
2020-04-16 00:16:00 +00:00
mini=i;
2020-04-16 13:16:09 +00:00
for(int j=i+1;j<=count;j++){
2020-04-16 15:52:59 +00:00
if(strcmp(min,list[j].fname)>0){
2020-04-16 15:51:03 +00:00
min=list[j].fname;
mini=j;
2020-04-16 15:43:37 +00:00
}
2020-04-16 00:16:00 +00:00
}
2020-04-16 19:09:03 +00:00
ilusion=list[i];
list[i]=list[mini];
list[mini]=ilusion;
2020-04-16 00:16:00 +00:00
}
}
2020-04-16 13:16:09 +00:00
2020-04-16 00:16:00 +00:00
void print(struct LIS *list,int count,int places){
2020-04-16 13:31:07 +00:00
if(count>0){
2020-04-16 13:16:09 +00:00
if(places>0){
2020-04-16 19:49:16 +00:00
printf("Prijati studenti:\n");
2020-04-16 20:40:19 +00:00
for(int i=0;i<count+count;i++){
if(list[i].num>0){
2020-04-16 19:22:15 +00:00
fputs(list[i].fname,stdout);
2020-04-16 13:16:09 +00:00
}
}
}
if(count-places>0){
2020-04-16 19:22:15 +00:00
printf("Neprijati studenti:\n");
2020-04-16 20:40:19 +00:00
for(int i=0;i<count+count;i++){
2020-04-16 19:09:03 +00:00
if(list[i].num==0){
2020-04-16 19:22:15 +00:00
fputs(list[i].fname,stdout);
2020-04-16 13:16:09 +00:00
}
2020-04-16 19:09:03 +00:00
}
2020-04-16 00:16:00 +00:00
}
}
2020-04-16 15:51:03 +00:00
}
2020-04-16 20:40:19 +00:00
void AAAAA(struct LIS* list, int count,int places){
int k=1;
for(int i=0;i<100;i++){
if(k!=places+1){
if(list[i].num==0){
list[i].num=k;
k++;
}
}
}
printf("%d",k);
}
2020-04-16 15:57:43 +00:00