Advertisement
zsoltizbekk

legjobb

Apr 15th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct elem
  5. {
  6.   char prog[21],ceg[21];
  7.   float szam;
  8.  
  9. }ELEM;
  10.  
  11. int rendez( const void *a, const void *b )
  12. {
  13.   ELEM *pa = (ELEM * )a;
  14.   ELEM *pb = (ELEM * )b;
  15.  
  16.   if ( (*pa).szam > (*pb).szam )
  17.     return -1;
  18.   else if ( (*pa).szam < (*pb).szam )
  19.     return 1;
  20.   else
  21.     return strcmp((*pa).ceg,(*pb).ceg);
  22.  
  23. }
  24.  
  25. int main()
  26. {
  27.  
  28.     ELEM t[ 100 ];
  29.     int index,i=0;
  30.     char p[21],c[21];
  31.     float sz;
  32.  
  33.     while( scanf("%s %s %f",p,c,&sz) != EOF )
  34.     {
  35.         strcpy( t[i].prog, p );
  36.         strcpy( t[i].ceg, c );
  37.         t[i].szam=sz;
  38.         i++;
  39.     }
  40.     if(i<3) index=i;
  41.     else index=3;
  42.  
  43.     qsort( t, i, sizeof( ELEM ), rendez );
  44.  
  45.     for ( i = 0; i<index ; ++i )
  46.     printf( "%s %s %.1f\n", t[i].prog, t[i].ceg, t[i].szam );
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement