Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #ifndef DEBUG
  5. #define DEBUG(...) printf(__VA_ARGS__)
  6. #endif
  7.  
  8. #define SIZE 1000
  9.  
  10. typedef struct{
  11.   char jmbag[32];
  12.   char ime[32];
  13.   char prezime[32];
  14.   char datum[20];
  15. }student;
  16.  
  17. typedef struct{
  18.   char c;
  19.   char string[32];
  20. }search;
  21.  
  22. int compare(student s1, student s2){
  23.   return (strcmp(s1.jmbag, s2.jmbag));
  24. }
  25.  
  26.  
  27. void sort (student array[], int n){
  28.   for (int i = 1; i < n; i++) {
  29.     student tmp = array[i];
  30.     int j = i;
  31.  
  32.     while (j > 0 && compare(array[j - 1], tmp) > 0) {
  33.         array[j] = array[j - 1];
  34.         j--;
  35.     }
  36.  
  37.     array[j] = tmp;
  38.   }
  39. }
  40.  
  41.  
  42.  
  43. int main() {
  44.  
  45.   int n, m;
  46.   student s[SIZE];
  47.   search unos[SIZE];
  48.  
  49.   scanf ("%d", &n);
  50.  
  51.   for (int i = 0; i < n; ++i){
  52.     scanf ("%s %s %s %s\n", s[i].jmbag, s[i].ime, s[i].prezime, s[i].datum);
  53.   }
  54.  
  55.   scanf ("%d\n", &m);
  56.  
  57.   for (int i = 0; i < m; ++i){
  58.     scanf ("%c %s\n", &unos[i].c, unos[i].string);
  59.   }
  60.  
  61.   sort(s, n);
  62.  
  63.  
  64.   for (int i = 0; i < m; ++i){
  65.     int flag = 1;
  66.     switch(unos[i].c){
  67.       case'I':
  68.         flag = 1;
  69.         printf("Ime: %s\n", unos[i].string );
  70.         for (int j = 0; j < n; ++j){
  71.           if (unos[i].string == s[j].ime){
  72.             flag = 0;
  73.             printf("%s %s %s %s\n", s[j].jmbag, s[j].prezime, s[j].ime, s[j].datum);
  74.           }
  75.         }
  76.         if (flag){
  77.           printf("-\n");
  78.         }
  79.         break;
  80.       case'P':
  81.         printf("Prezime: %s\n", unos[i].string );
  82.         break;
  83.       case'J':
  84.         printf("JMBAG: %s\n", unos[i].string );
  85.         break;
  86.     }
  87.   }
  88.  
  89.   return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement