Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cstdlib>
  5. #include <time.h>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. const int N = 100000;
  12. int Z [ N ], i, j, L, W, maxL, maxW;
  13.  
  14. // Generujemy zawartość Z [ ]
  15.  
  16. srand((unsigned)time(NULL));
  17. for(i = 0; i < N; i++) Z [ i ] = 50 + rand() % 41;
  18.  
  19. // Wyszukujemy najczęstszą wartość
  20.  
  21. maxL = 0;
  22. for(i = 0; i < N; i++)
  23. {
  24. W = Z [ i ]; L = 0;
  25. for(j = 0; j < N; j++) if(Z [ j ] == W) L++;
  26. if(L > maxL)
  27. {
  28. maxL = L; maxW = W;
  29. }
  30. }
  31.  
  32. // Wypisujemy tablicę
  33.  
  34. // for(i = 0; i < N; i++)
  35. // if(Z [ i ] == maxW) cout << " >" << setw(2) << Z [ i ];
  36. // else cout << setw(4) << Z [ i ];
  37.  
  38. // Wypisujemy najczęstszy element oraz liczbę wystąpień
  39.  
  40. cout << endl << maxW << ": " << maxL << endl << endl;
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement