Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- struct elem
- {
- char nev[35];
- int eredmeny;
- };
- int hasonlit (const void *p1, const void*p2)
- {
- struct elem f1 = *(const struct elem *)p1;
- struct elem f2 = *(const struct elem *)p2;
- if (f1.eredmeny > f2.eredmeny)
- {
- return -1;
- }
- if (f1.eredmeny < f2.eredmeny)
- {
- return 1;
- }
- if (f1.eredmeny == f2.eredmeny)
- {
- return strcmp(f1.nev,f2.nev);
- }
- return 0;
- }
- int main()
- {
- int db = 0;
- int *nevecske;
- struct elem el;
- struct elem *tomb = malloc(21*sizeof(el));
- int hossz;
- int t[20];
- int i;
- int count = 0;
- int ertek = 0;
- int nov = 0;
- char *sor = malloc(100*sizeof(char));
- while(gets(sor)!=NULL)
- {
- nevecske = strtok(sor,"/");
- hossz = strlen(nevecske);
- for ( i = hossz+1; i < hossz+22; i++ )
- {
- t[count] = sor[i]-'0';
- count++;
- }
- for (i = 0; i < 20; i++)
- {
- if (t[i] == 2)
- {
- ertek = ertek + 1;
- }
- }
- if (ertek > 2)
- {
- tomb[nov].eredmeny = ertek;
- strcpy(tomb[nov].nev,nevecske);
- //printf("%s ", nevecske);
- nov++;
- }
- count = 0;
- ertek = 0;
- if(db == 19)
- break;
- db++;
- }
- qsort (tomb,nov, sizeof(el), hasonlit);
- for ( i = 0; i < nov; i++)
- {
- printf("%s\n", tomb[i].nev);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement