Aktualizovat „du6/program.c“

This commit is contained in:
Bohdan Yanchyk 2020-04-16 07:39:38 +00:00
parent 41776796ca
commit d26f313f9d

View File

@ -1,101 +1,102 @@
/****************************************************************************** /******************************************************************************
Welcome to GDB Online. Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world. Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/ *******************************************************************************/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#define fullSIZE = 1000 #define fullSIZE 1000
#define wSIZE = 100 #define wSIZE 100
#include <string.h> #include <string.h>
int main() int main()
{ {
int SIZE = 0; int SIZE = 0;
if(!(scanf("%d", &SIZE))){ if(!(scanf("%d", &SIZE))){
printf("Nespravny vstup\n"); printf("Nespravny vstup\n");
return 0; return 0;
} }
if(SIZE < 1){ if(SIZE < 1){
printf("Nespravny vstup\n"); printf("Nespravny vstup\n");
return 0; return 0;
} }
int pm = 0; int pm = 0;
char** pole_smernikov = malloc(fullSIZE * sizeof(char)); char** pole_smernikov = malloc(fullSIZE * sizeof(char));
char* success[SIZE]; //char* success[SIZE];
char* unsuccess[SIZE]; //char* unsuccess[SIZE];
//memset(pole_smernikov,0,SIZE*sizeof(char*)); //memset(pole_smernikov,0,SIZE*sizeof(char*));
int k = 0; int k = 0;
char* line = malloc(wSIZE * sizeof(char)); char* line = malloc(wSIZE * sizeof(char));
memset(line,0,SIZE); memset(line,0,SIZE);
char* r; //char* r;
int q = 0; //int q = 0;
int pocet_znakov = 0; int pocet_znakov = 0;
while (fgets(line,SIZE,stdin)) { while (fgets(line,SIZE,stdin)) {
pocet_znakov = strlen(line); pocet_znakov = strlen(line);
char* all = malloc(pocet_znakov); char* all = malloc(pocet_znakov);
memcpy(all, line, pocet_znakov); memcpy(all, line, pocet_znakov);
for(int x = 0; x < pm; x++){ for(int x = 0; x < pm; x++){
if(memcmp(pole_smernikov[x], line, pocet_znakov) == 0){ if(memcmp(pole_smernikov[x], line, pocet_znakov) == 0){
k++; k++;
} }
pole_smernikov[k] = line; pole_smernikov[k] = line;
} }
if(0 == k){ if(0 == k){
pole_smernikov[pm] = all; pole_smernikov[pm] = all;
pm++; pm++;
} }
} }
k = 0; k = 0;
int i = 0; int i = 0;
while (i < pm){ i = 0;
for(int j = 0+1; j < pm-i; j++){ while (i < pm){
if(0 < strcmp(pole_smernikov[j-1], pole_smernikov[j])){ for(int j = 0+1; j < pm-i; j++){
char* temp = pole_smernikov[j]; if(0 < strcmp(pole_smernikov[j-1], pole_smernikov[j])){
pole_smernikov[j] = pole_smernikov[j - 1]; char* temp = pole_smernikov[j];
pole_smernikov[j-1] = temp; pole_smernikov[j] = pole_smernikov[j - 1];
} pole_smernikov[j-1] = temp;
} }
// if (memcmp(pole_smernikov[i],line,pocet_znakov)){ }
// // Nasiel som // if (memcmp(pole_smernikov[i],line,pocet_znakov)){
// unsuccess[k] = pole_smernikov[i]; // // Nasiel som
// printf("%s\n", unsuccess[k]); // unsuccess[k] = pole_smernikov[i];
// } else{ // printf("%s\n", unsuccess[k]);
// success[q] = pole_smernikov[i]; // } else{
// printf("%s\n", success[q]); // success[q] = pole_smernikov[i];
// printf("%s\n", success[q]);
// }
i++; // }
} i++;
if(NULL == pole_smernikov[1]){ }
puts("Ziadne prihlasky"); if(NULL == pole_smernikov[1]){
return 0; puts("Ziadne prihlasky");
} return 0;
puts("Prijati studenti:"); }
for(int i = 0; i < SIZE; i++){ puts("Prijati studenti:");
if(pole_smernikov[i] == NULL){ for(int i = 0; i < SIZE; i++){
break; if(pole_smernikov[i] == NULL){
} else{ break;
printf("%s\n", pole_smernikov[i]); } else{
} printf("%s\n", pole_smernikov[i]);
free(pole_smernikov[i]); }
} free(pole_smernikov[i]);
int rra = -1; }
pm = pm + rra; int rra = -1;
if(0 > (SIZE - pm)){ pm = pm + rra;
puts("Neprijati studenti:"); if(0 > (SIZE - pm)){
for(int i = SIZE+1; i<pm+1; i++){ puts("Neprijati studenti:");
printf("%s\n", pole_smernikov[i]); for(int i = SIZE+1; i<pm+1; i++){
printf("%s\n", pole_smernikov[i]);
free(pole_smernikov[i]);
} free(pole_smernikov[i]);
} }
free(pole_smernikov); }
free(pole_smernikov);
return 0;
} return 0;
}