Advertisement
Guest User

Untitled

a guest
May 27th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int tomb[] = {12, 47, 314, 47, 51, 52, 47};
  8.  
  9.     int i, j;
  10.  
  11.     for(j = sizeof(tomb) / sizeof(tomb[0]); j > 0; j--)
  12.     {
  13.         for(i = 0; i < (j - 1); i++)
  14.         {
  15.             if(tomb[i] > tomb[i + 1])
  16.             {
  17.                 int csere;
  18.                 csere = tomb[i + 1];
  19.                 tomb[i + 1] = tomb[i];
  20.                 tomb[i] = csere;
  21.             }
  22.         }
  23.     }
  24.     int akt_szam = 0, szam = 0, akt_elofordulas = 1, elofordulas = 0;
  25.  
  26.     akt_szam = tomb[0];
  27.     szam = tomb[0];
  28.     for(i = 0; i < ( sizeof(tomb) / sizeof(tomb[0]) - 1 ); i++)
  29.     {
  30.  
  31.         if(tomb[i] == tomb[i + 1])
  32.         {
  33.                 akt_elofordulas++;
  34.         }
  35.         else
  36.         {
  37.             if(akt_elofordulas > elofordulas)
  38.             {
  39.                 elofordulas = akt_elofordulas;
  40.                 szam = akt_szam;
  41.             }
  42.             akt_szam = tomb[i + 1];
  43.             akt_elofordulas = 1;
  44.         }
  45.         if(i == sizeof(tomb) / sizeof(tomb[0]) - 2)
  46.            {
  47.             if(akt_elofordulas > elofordulas)
  48.             {
  49.                 elofordulas = akt_elofordulas;
  50.                 szam = akt_szam;
  51.             }
  52.            }
  53.     }
  54.  
  55.     cout << "A(z) " << szam << " " << elofordulas << " alkalommal fordul elo.";
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement