Advertisement
VSZM

Struktúrák

Apr 25th, 2014
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. typedef struct
  6. {
  7.     char Brand[30];
  8.     char Model[30];
  9.     int Year;
  10. }Car;
  11.  
  12. int Car_Cmp(const void* _a, const void* _b)
  13. {
  14.     Car a = *(Car*)_a, b = *(Car*)_b;
  15.     if(strcmp(a.Brand, b.Brand)  == 0) // Nem tudunk márka alapján dönteni
  16.     {
  17.         if(strcmp(a.Model,b.Model) == 0) // Nem tudunk modell alapján dönteni
  18.         {
  19.             return b.Year - a.Year;
  20.         }
  21.         else return strcmp(a.Model,b.Model);
  22.     }
  23.     else return strcmp(a.Brand, b.Brand);
  24. }
  25.  
  26. int main(int argc, char** argv)
  27. {
  28.     int i = 0, j, kiirt = 0;
  29.     Car Cars[1000];
  30.  
  31.     while(scanf("%s", Cars[i].Brand) > -1)
  32.     {
  33.         scanf("%s", Cars[i].Model);
  34.         scanf("%d", &Cars[i].Year);
  35.         ++i;   
  36.     }
  37.  
  38.     qsort(Cars, i, sizeof(Car), Car_Cmp);
  39.     for(j = 0; j < i &&  kiirt < atoi(argv[2]); ++j)
  40.     {
  41.         if(strcmp(Cars[j].Brand, argv[1]) == 0)
  42.         {
  43.             kiirt ++;
  44.             printf("%s %s %d\n", Cars[j].Brand, Cars[j].Model, 2014-Cars[j].Year);
  45.         }
  46.     }  
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement