Advertisement
Guest User

das

a guest
May 30th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. struct hallgatok
  7. {
  8.     char nev[50];
  9.     int eredmenyek;
  10.     int maxpont;
  11.     double arany;
  12. };
  13.  
  14. int hasonlit (const void *p1, const void*p2)
  15. {
  16. struct hallgatok f1 = *(const struct hallgatok *)p1;
  17. struct hallgatok f2 = *(const struct hallgatok *)p2;
  18.     if (f1.arany > f2.arany)
  19.     {
  20.         return 1;
  21.     }
  22.     if (f1.arany < f2.arany)
  23.     {
  24.         return -1;
  25.     }
  26.     if (f1.arany == f2.arany)
  27.     {
  28.         return strcmp(f1.nev,f2.nev);
  29.     }
  30.     return 0;
  31. }
  32.  
  33. int main()
  34. {
  35.     struct hallgatok hallg;
  36.     struct hallgatok *tomb = malloc (21 * sizeof(hallg));
  37.     char *sor = malloc (100000000000*sizeof(char));
  38.     char *nevecske;
  39.     char *tok;
  40.     char *tok2;
  41.     char *tok3;
  42.  
  43.     int pontos;
  44.     int pontos2;
  45.     int pontos1;
  46.  
  47.     int ered;
  48.     int max = 0;
  49.     double ertek;
  50.  
  51.     double convert1;
  52.     double convert2;
  53.  
  54.     int szamolo = 0;
  55.     int nov = 0;
  56.     int db = 0;
  57.  
  58.     int hossz;
  59.     int hossz2;
  60.     int a = 0;
  61.  
  62.     int i;
  63.     while(gets(sor))
  64.     {
  65.         hossz = strlen(sor);
  66.         nevecske = strtok(sor,":");
  67.         hossz2 = strlen(nevecske);
  68. //        printf("%d %d",hossz, hossz2 + 1);
  69.         tok3 = strtok (NULL,"/");
  70.         pontos = atoi(tok3);
  71.         ered = pontos;
  72.         if( hossz == hossz2+1 )
  73.         {
  74.             a = a + 1;
  75.         }
  76.         else
  77.         {
  78.             while (tok = strtok(NULL,","))
  79.             {
  80.             szamolo = szamolo + 1;
  81.             pontos2 = atoi(tok);
  82.             max = max + pontos2;
  83.             tok2 = strtok(NULL,"/");
  84.             pontos1 = atoi(tok2);
  85.             ered = ered + pontos1;
  86.             }
  87.             convert1 = max;
  88.             convert2 = ered;
  89.             ertek = convert1 / convert2;
  90.             if (max / ered <= 2)
  91.             {
  92.                 tomb[nov].eredmenyek = ered;
  93.                 tomb[nov].maxpont = max;
  94.                 strcpy(tomb[nov].nev,nevecske);
  95.                 tomb[nov].arany = ertek;
  96.                 nov++;
  97.             }
  98.         }
  99.         ered = 0;
  100.         max = 0;
  101.         if (db == 19)
  102.             break;
  103.         db++;
  104.     }
  105.     qsort (tomb,nov, sizeof(hallg), hasonlit);
  106.     for ( i = 0; i < nov; i++)
  107.     {
  108.         printf("%s (%d/%d)\n", tomb[i].nev,tomb[i].eredmenyek,tomb[i].maxpont);
  109.     }
  110.     return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement