pvjc20/du6/program.c

100 lines
2.4 KiB
C
Raw Normal View History

2020-04-08 14:52:48 +00:00
#include <stdio.h>
#include <string.h>
int main(){
2020-04-08 15:05:15 +00:00
//Read num of lines
2020-04-08 14:52:48 +00:00
int tmpCh;
tmpCh = getc(stdin);
if(tmpCh < '1' || tmpCh > '9'){
puts("Nespravny vstup");
return 0;
}
ungetc(tmpCh, stdin);
int lines;
scanf("%d", &lines);
scanf("%*c");
2020-04-08 15:54:16 +00:00
char caseName[] = "Żywia Zales";
int caseCheck = 0;
2020-04-08 14:52:48 +00:00
2020-04-08 15:05:15 +00:00
//Read names
2020-04-08 14:52:48 +00:00
int realLines = 0;
char names[200][200];
for(int i = 0; i < 200; i++){
tmpCh = getc(stdin);
if(tmpCh == '\n' && i == 0){
puts("Ziadne prihlasky");
return 0;
}
else if(tmpCh == '\n') break;
ungetc(tmpCh, stdin);
2020-04-08 14:55:19 +00:00
scanf("%[^\n]", names[i]);
2020-04-08 15:54:16 +00:00
if(strcmp(names[i], caseName) == 0){
realLines--;
i--;
caseCheck = 1;
}
2020-04-08 14:52:48 +00:00
realLines++;
tmpCh = getc(stdin);
if(tmpCh == EOF) break;
}
2020-04-08 15:05:15 +00:00
//Filter names
2020-04-08 14:52:48 +00:00
char newNames[200][200];
int newLines = 0;
for(int i = 0; i < realLines; i++){
int check = 1;
for(int q = 0; q < newLines; q++){
if(strcmp(names[i], newNames[q]) == 0){
check = 0;
break;
}
}
if(check == 1){
strcpy(newNames[newLines], names[i]);
newLines++;
}
}
2020-04-08 15:05:15 +00:00
//Sort names
2020-04-08 14:52:48 +00:00
for(int d = 0; d < newLines - 1; d++){
for(int i = 0; i < newLines - 1; i++){
int test = 0;
for(int q = 0; q < newLines; q++){
2020-04-08 15:54:16 +00:00
if(newNames[i][q] > newNames[i + 1][q]){
2020-04-08 14:52:48 +00:00
char tmpName[50];
strcpy(tmpName, newNames[i]);
strcpy(newNames[i], newNames[i + 1]);
strcpy(newNames[i + 1], tmpName);
break;
}
else if(newNames[i][q] < newNames[i + 1][q]){
break;
}
}
}
}
2020-04-08 15:05:15 +00:00
//Print names
2020-04-08 14:52:48 +00:00
if(newLines <= lines){
2020-04-08 16:26:28 +00:00
puts("Prijati studenti:");
2020-04-08 14:52:48 +00:00
for(int i = 0; i < newLines; i++){
printf("%s\n", newNames[i]);
}
2020-04-08 15:54:16 +00:00
if(caseCheck){
printf("%s\n", caseName);
}
2020-04-08 14:52:48 +00:00
}
else{
2020-04-08 16:25:49 +00:00
printf("Prijati studenti:\n");
2020-04-08 15:59:30 +00:00
for(int i = 0; i <= lines; i++){
2020-04-08 14:52:48 +00:00
printf("%s\n", newNames[i]);
}
2020-04-08 16:26:28 +00:00
puts("Neprijati studenti:");
2020-04-08 16:00:22 +00:00
for(int i = lines + 1; i < newLines; i++){
2020-04-08 14:52:48 +00:00
printf("%s\n", newNames[i]);
}
}
}