Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- using namespace std;
- int& max(int* arr, int N, int nepodh = LONG_MAX) {
- int indmax = 0;
- bool repet = false;
- int itercount = 0;
- for (int i = 1; i < N; i++) {
- if (arr[i] > arr[indmax] && arr[i] < nepodh) {
- itercount++;
- indmax = i;
- repet = false;
- continue;
- }
- else if (arr[i] == arr[indmax]) {
- repet = true;
- }
- }
- if (!repet) return arr[indmax];
- else {
- if (!itercount) {
- indmax = 0;
- for (int i = 1; i < N; i++)
- if (arr[i] > arr[indmax])
- indmax = i;
- return arr[indmax];
- }
- nepodh = arr[indmax];
- return max(arr, N, nepodh);
- }
- }
- void print(int* arr, int N) {
- for (int i = 0; i < N; i++) {
- cout << arr[i] << " ";
- }
- cout << endl;
- }
- int main(){
- int A[] = { 11,11,2,2,3,3,4, 4, 10,10 };
- int N = sizeof(A) / 4;
- int n;
- cout << "n = ";
- cin >> n;
- if (n) {
- int* a = new int[n];
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- }
- cout << max(a, n) << endl;
- max(a, n) = 0;
- print(a, n);
- return 0;
- }
- cout << "max = " << max(A, N) << endl;
- max(A, N) = 0;
- print(A, N);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement