Přidat 'zsiKOD'

This commit is contained in:
Michal Čabra 2019-05-13 09:27:51 +00:00
parent 6118bfb3c0
commit 02253d0d43

136
zsiKOD Normal file
View File

@ -0,0 +1,136 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int compare(const void *a, const void *b)
{
const char **pa,**pb;
pa = (const char **)a;
pb = (const char **)b;
return( strcmp(*pa,*pb) );
}
int main() {
int pocet_slov,pocet_znakov=0,i=0,count=0,number=0;
bool zhoda=false;
char* pole_smernikov[1000]={0};
char line[1000];
char cislo[1000];
fgets(cislo,1000,stdin);
int dlzka=strlen(cislo);
for(i=0;i<dlzka;i++){
if(isdigit(cislo[i])){
number=number*10;
number+=cislo[i]-'0';
}
else if(cislo[i]==' ' || cislo[i]=='\n' || cislo[i]==' '){
;
}
else{
puts("Nespravny vstup");
return 0;
}
}
//printf("prijaty: %d\n",number);
if(number==0){
puts("Nespravny vstup");
return 0;
}
while(fgets(line,1000,stdin)!=NULL){
if(strlen(line)<1){
return 0;
}
pocet_znakov=strlen(line);
//printf("Pocet znakov: %d\n",pocet_znakov);
for(i=0;i<pocet_znakov;i++){
if(line[i]>='A' && line[i]<='Z')count++;
if(line[i]>='a' && line[i]<='z')count++;
}
if(count==0){
//printf("Koniec");
break;
}
int size = (int)strlen(line);
size--;
while(size!=-1){
if(line[size]==' ' || line[size]=='\n' || line[size]==' '){
line[size]='\0';
}
else{
break;
}
size--;
}
//printf("Retazec: #%s#\n",line);
for(i=0;i<pocet_slov;i++){
char *str1=pole_smernikov[i];
if(strcmp(str1,line)==0)zhoda=true;
}
if(!zhoda){
// printf("Pridavam!\n");
pole_smernikov[pocet_slov] = malloc(pocet_znakov + 1);
memcpy(pole_smernikov[pocet_slov],line,pocet_znakov + 1);
pocet_slov += 1;
}
count=0;
zhoda=false;
}
if(pocet_slov==0){
puts("Ziadne prihlasky");
return 0;
}
for (i = 0; i < pocet_slov; i++){
int size = (int)strlen(pole_smernikov[i]);
size--;
while(size!=0){
if(pole_smernikov[i][size]==' ' || pole_smernikov[i][size]=='\n' || pole_smernikov[i][size]==' '){
pole_smernikov[i][size]='\0';
}
else{
break;
}
size--;
}
//printf("%d: %s\n",i+1,pole_smernikov[i]);
}
qsort(pole_smernikov,pocet_slov,sizeof(char *),compare);
//printf("Sorted:\n");
if(pocet_slov<=number && number>0){
puts("Prijati studenti:");
for (i = 0; i < pocet_slov; i++){
printf("%s\n",pole_smernikov[i]);
}
}
else{
puts("Prijati studenti:");
for (i = 0; i < number; i++){
printf("%s\n",pole_smernikov[i]);
}
puts("Neprijati studenti:");
for (i = number; i < pocet_slov; i++){
printf("%s\n",pole_smernikov[i]);
}
}
for (i = 0; i < pocet_slov; i++){
free(pole_smernikov[i]);
}
return 0;
}