Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <ctime>
- #include <iomanip>
- using namespace std;
- int& min(vector<int> a)
- {
- int n = a.size();
- int k = 1;
- int p = n;
- int &rmax = a[0];
- for (int i = 0; i <= n - 2; i++)
- {
- for(int j = 1; j <= n - 1; j++)
- if (a[i] == a[j])
- {
- k++;
- }
- if (k < p)
- {
- p = k;
- rmax = rmax < a[i] ? a[i] : rmax; // fix
- }
- k = 1;
- }
- return rmax;
- }
- int main()
- {
- //int a[] = { 7, 7, 3, 4, 0, 1, 5, 6 };
- srand(time(NULL));
- int n;
- cin >> n;
- vector <int> a(n);
- for (int i = 0; i <= n - 1; i++)
- {
- a[i] = rand() % 10;
- cout << a[i] << setw(3);
- }
- cout<<endl;
- //int* pr= &a[0];
- cout << min(a);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement