Advertisement
Guest User

Untitled

a guest
May 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4.  
  5. typedef struct orszag{
  6.     char nev[100];
  7.     int zaszlo;
  8. }ORSZAG;
  9.  
  10. int cmp(const void *a, const void *b)
  11. {
  12.     ORSZAG x = *((ORSZAG*) a);
  13.     ORSZAG y = *((ORSZAG*) b);
  14.     if((y.zaszlo-x.zaszlo)!=0)  return y.zaszlo-x.zaszlo;
  15.     else return (strcmp(x.nev, y.nev));
  16. }
  17.  
  18.  
  19. int main(int argc, char* argv[])
  20. {
  21.     int orszag=0;
  22.     FILE*f=fopen(argv[1],"r");
  23.     char s[1000];
  24.    
  25.     while( fgets(s,1000,f) != NULL )
  26.     {
  27.         orszag++;
  28.     }
  29.     fseek(f,0,SEEK_SET);
  30.    
  31.    
  32.     ORSZAG x[orszag];
  33.  
  34.     int i,max=0;
  35.  
  36.     int y1=0;
  37.     while( fgets(s,1000,f) != NULL )
  38.     {
  39.         x[y1].zaszlo=0;
  40.         strcpy(x[y1].nev,strtok(s,";"));
  41.         while(strtok(NULL,";")!=NULL)
  42.         {
  43.             x[y1].zaszlo++;
  44.         }
  45.         if(x[y1].zaszlo>max)
  46.             max=x[y1].zaszlo;
  47.         y1++;
  48.     }
  49.  
  50.    
  51.     qsort(x, y1, sizeof(ORSZAG), cmp); 
  52.    
  53.     for(i=0;i<y1;i++)
  54.     {
  55.         if(x[i].zaszlo==max)
  56.             printf("%s\n",x[i].nev);
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement