pvjc22/du6/program.c

81 lines
2.0 KiB
C
Raw Normal View History

2022-04-22 07:13:13 +00:00
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define SIZE 100
2022-04-22 06:54:35 +00:00
2022-04-22 07:13:13 +00:00
int compare(const void* arg1, const void* arg2);
2022-04-22 06:54:35 +00:00
2022-04-22 07:13:13 +00:00
int main(){
2022-04-22 06:54:35 +00:00
2022-04-22 07:13:13 +00:00
char* pole_smernikov[SIZE];
memset(pole_smernikov,0,SIZE*sizeof(char*));
int pocet_mien_v_poli=0;
2022-04-22 07:28:51 +00:00
int p = 0;
scanf("%d",&p);
getchar();
2022-04-22 07:13:13 +00:00
while(1){
char line[SIZE];
memset(line,0,SIZE);
char* r = fgets(line,SIZE,stdin);
2022-04-22 07:28:51 +00:00
int pocet_znakov=0;
2022-04-22 07:13:13 +00:00
if(!r||r[0]=='\n')break;
else pocet_znakov=strlen(line);
2022-04-22 07:28:51 +00:00
int skip=0;
2022-04-22 07:13:13 +00:00
for (int i=0;skip==0&&i<pocet_mien_v_poli; i++){
if (!memcmp(pole_smernikov[i],line,pocet_znakov)){
skip=1;
}
}
if(!skip){
pole_smernikov[pocet_mien_v_poli]=malloc(pocet_znakov + 1);
memcpy(pole_smernikov[pocet_mien_v_poli],line,pocet_znakov + 1);
pocet_mien_v_poli++;
}
}
2022-04-22 07:40:00 +00:00
qsort(pole_smernikov, pocet_mien_v_poli, sizeof(char*), compare);
2022-04-22 07:35:15 +00:00
int skip=0;
2022-04-22 07:41:25 +00:00
for(int j = 0;skip==0&& j<pocet_mien_v_poli ;j++){
for(int i=0;skip==0&&i<strlen(pole_smernikov[j]);i++){
2022-04-22 07:43:07 +00:00
if(pole_smernikov[j][i]>='0'&&pole_smernikov[j][i]<='9'){
2022-04-22 07:41:25 +00:00
printf("Nespravny vstup\n");
2022-04-22 07:35:15 +00:00
skip=1;
2022-04-22 07:28:51 +00:00
}
}
2022-04-22 07:41:25 +00:00
}
2022-04-22 07:35:15 +00:00
if (!skip){
printf("Prijati studenti:\n");
for(int i = 0; i<p && i<pocet_mien_v_poli ;i++)
printf("%s",pole_smernikov[i]);
if(p<pocet_mien_v_poli)printf("Neprijati studenti:\n");
for(int i = p; i<pocet_mien_v_poli ;i++)
printf("%s",pole_smernikov[i]);
}
for(int i = 0;i<pocet_mien_v_poli;i++)
free(pole_smernikov[i]);
2022-04-22 07:13:13 +00:00
return 0;
2022-04-22 06:54:35 +00:00
}
2022-04-22 07:13:13 +00:00
int compare(const void* arg1, const void* arg2){
char* s1 = *((char**)arg1);
char* s2 = *((char**)arg2);
int r = strcmp(s1,s2);
return r;
}