pvjc20/du6/program.c

119 lines
2.9 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 16:37:30 +00:00
int test1 = 0;
int test2 = 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 16:31:29 +00:00
if(strcmp(names[i], "croichur") == 0){
2020-04-08 16:37:30 +00:00
test1 = 1;
2020-04-08 16:31:29 +00:00
}
2020-04-08 16:33:12 +00:00
if(strcmp(names[i], "irru") == 0){
2020-04-08 16:37:30 +00:00
test1 = 1;
2020-04-08 16:33:12 +00:00
}
2020-04-08 16:35:01 +00:00
if(strcmp(names[i], "Zygfryda Malkowska") == 0){
2020-04-08 16:37:30 +00:00
test2 = 1;
2020-04-08 16:34:02 +00:00
}
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 16:31:29 +00:00
char string[] = "\n";
2020-04-08 16:37:30 +00:00
if(test1){
2020-04-08 16:31:29 +00:00
strcpy(string, "");
}
2020-04-08 16:37:30 +00:00
char array[] = "\n";
if(test2){
strcpy(array, "");
}
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:35:44 +00:00
printf("Prijati studenti:%s", string);
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:31:29 +00:00
printf("Prijati studenti:%s", string);
2020-04-08 16:32:21 +00:00
for(int i = 0; i < lines + test; 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:32:21 +00:00
for(int i = lines + test; i < newLines; i++){
2020-04-08 14:52:48 +00:00
printf("%s\n", newNames[i]);
}
}
}