Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- struct hallgatok
- {
- char nev[50];
- int eredmenyek;
- int maxpont;
- double arany;
- };
- int hasonlit (const void *p1, const void*p2)
- {
- struct hallgatok f1 = *(const struct hallgatok *)p1;
- struct hallgatok f2 = *(const struct hallgatok *)p2;
- if (f1.arany > f2.arany)
- {
- return 1;
- }
- if (f1.arany < f2.arany)
- {
- return -1;
- }
- if (f1.arany == f2.arany)
- {
- return strcmp(f1.nev,f2.nev);
- }
- return 0;
- }
- int main()
- {
- struct hallgatok hallg;
- struct hallgatok *tomb = malloc (21 * sizeof(hallg));
- char *sor = malloc (100000000000*sizeof(char));
- char *nevecske;
- char *tok;
- char *tok2;
- char *tok3;
- int pontos;
- int pontos2;
- int pontos1;
- int ered;
- int max = 0;
- double ertek;
- double convert1;
- double convert2;
- int szamolo = 0;
- int nov = 0;
- int db = 0;
- int hossz;
- int hossz2;
- int a = 0;
- int i;
- while(gets(sor))
- {
- hossz = strlen(sor);
- nevecske = strtok(sor,":");
- hossz2 = strlen(nevecske);
- // printf("%d %d",hossz, hossz2 + 1);
- tok3 = strtok (NULL,"/");
- pontos = atoi(tok3);
- ered = pontos;
- if( hossz == hossz2+1 )
- {
- a = a + 1;
- }
- else
- {
- while (tok = strtok(NULL,","))
- {
- szamolo = szamolo + 1;
- pontos2 = atoi(tok);
- max = max + pontos2;
- tok2 = strtok(NULL,"/");
- pontos1 = atoi(tok2);
- ered = ered + pontos1;
- }
- convert1 = max;
- convert2 = ered;
- ertek = convert1 / convert2;
- if (max / ered <= 2)
- {
- tomb[nov].eredmenyek = ered;
- tomb[nov].maxpont = max;
- strcpy(tomb[nov].nev,nevecske);
- tomb[nov].arany = ertek;
- nov++;
- }
- }
- ered = 0;
- max = 0;
- if (db == 19)
- break;
- db++;
- }
- qsort (tomb,nov, sizeof(hallg), hasonlit);
- for ( i = 0; i < nov; i++)
- {
- printf("%s (%d/%d)\n", tomb[i].nev,tomb[i].eredmenyek,tomb[i].maxpont);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement