SHARE
TWEET

Untitled

a guest Feb 27th, 2020 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <ctime>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. int& min(vector<int> a)
  9. {
  10.     int n = a.size();
  11.     int k = 1;
  12.     int p = n;
  13.     int &rmax = a[0];
  14.     for (int i = 0; i <= n - 2; i++)
  15.     {
  16.         for(int j = 1; j <= n - 1; j++)
  17.         if (a[i] == a[j])
  18.         {
  19.             k++;
  20.         }
  21.         if (k < p)
  22.         {
  23.             p = k;
  24.             rmax = rmax < a[i] ? a[i] : rmax; // fix
  25.         }
  26.         k = 1;
  27.     }
  28.     return rmax;
  29. }
  30.  
  31. int main()
  32. {
  33.     //int a[] = { 7, 7, 3, 4, 0, 1, 5, 6 };
  34.     srand(time(NULL));
  35.     int n;
  36.     cin >> n;
  37.     vector <int> a(n);
  38.     for (int i = 0; i <= n - 1; i++)
  39.     {
  40.         a[i] = rand() % 10;
  41.         cout << a[i] << setw(3);
  42.     }
  43.     cout<<endl;
  44.     //int* pr= &a[0];
  45.     cout << min(a);
  46.     system("pause");
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top