Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- typedef struct
- {
- char Brand[30];
- char Model[30];
- int Year;
- }Car;
- int Car_Cmp(const void* _a, const void* _b)
- {
- Car a = *(Car*)_a, b = *(Car*)_b;
- if(strcmp(a.Brand, b.Brand) == 0) // Nem tudunk márka alapján dönteni
- {
- if(strcmp(a.Model,b.Model) == 0) // Nem tudunk modell alapján dönteni
- {
- return b.Year - a.Year;
- }
- else return strcmp(a.Model,b.Model);
- }
- else return strcmp(a.Brand, b.Brand);
- }
- int main(int argc, char** argv)
- {
- int i = 0, j, kiirt = 0;
- Car Cars[1000];
- while(scanf("%s", Cars[i].Brand) > -1)
- {
- scanf("%s", Cars[i].Model);
- scanf("%d", &Cars[i].Year);
- ++i;
- }
- qsort(Cars, i, sizeof(Car), Car_Cmp);
- for(j = 0; j < i && kiirt < atoi(argv[2]); ++j)
- {
- if(strcmp(Cars[j].Brand, argv[1]) == 0)
- {
- kiirt ++;
- printf("%s %s %d\n", Cars[j].Brand, Cars[j].Model, 2014-Cars[j].Year);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement