Advertisement
MeehoweCK

Untitled

Nov 30th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. minMaxRep(int a[], size_t size, int* min, size_t** cMin, int& max, size_t*& cMax)
  8. {
  9.     int tempMin = a[0];
  10.     int tempMinCount = 1;
  11.     int tempMax = a[0];
  12.     int tempMaxCount = 1;
  13.     for(int i = 1; i < size; i++)
  14.     {
  15.         if(a[i] < tempMin)
  16.         {
  17.             tempMin = a[i];
  18.             tempMinCount = 1;
  19.             continue;
  20.         }
  21.         if(a[i] == tempMin)
  22.             tempMinCount++;
  23.         if(a[i] > tempMax)
  24.         {
  25.             tempMax = a[i];
  26.             tempMaxCount = 1;
  27.             continue;
  28.         }
  29.         if(a[i] == tempMin)
  30.             tempMaxCount++;
  31.     }
  32.     *min = tempMin;
  33.     max = tempMax;
  34.     *cMax = tempMaxCount;
  35.     **cMin = tempMinCount;
  36. }
  37. int main()
  38. {
  39.     int tablica[20];
  40.     srand(static_cast<unsigned>(time(NULL)));
  41.     for(int i = 0; i < 20; ++i)
  42.     {
  43.         tablica[i] = rand() % 100;
  44.         cout << tablica[i] << " ";
  45.     }
  46.     cout << endl;
  47.     size_t* ccMin = new size_t;
  48.     int* min = new int;
  49.     size_t** cMin = &ccMin;
  50.     int max;
  51.     size_t* cMax = new size_t;
  52.     minMaxRep(tablica, 20, min, cMin, max, cMax);
  53.  
  54.     cout << *min << endl;
  55.     cout << **cMin << endl;
  56.     cout << max << endl;
  57.     cout << *cMax << endl;
  58.  
  59.     delete min;
  60.     delete ccMin;
  61.     delete cMax;
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement