awdaw

Kolorwanie:
Status:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
#include <iostream>
#include <stdio.h>
#include <time.h>

using namespace std;

int fun(int *tab, int size) {
    int maxsum = 0;
    int maxindex = 0;
    for (int i = 0; i < size; i++)
    {
        
        int sum = 0;
        int treshold = tab[i];
        while(treshold > 0) {
            if (!(treshold & 1)) {
                sum++;
            }
            treshold = treshold >> 1;
        }

        if(sum > maxsum) {
            maxsum = sum;
            maxindex = i;
        }
    }
    return maxindex;
}


int main() {

    int n, b, c;
    char a, d;
    cin >> n;
    cin >> a >> b;
    cin.ignore(1);
    cin >> c >> d;
    if(a == '(') {
        b++;
    }

    if(d == ')') {
        c--;
    }

    srand( time( NULL ) );
    int* tab = new int[n];
    for (int i = 0; i < n; i++)
    {
        tab[i] = rand() % (c - b) + b;
        cout << tab[i] << '\t';
    }
    int index = fun(tab, n);
    cout << endl << index << endl;

    int wynik = tab[index] ^ 4;
    cout << "po negacji = " << wynik;

    return 0;
}

Copyrights 2014-2021 © Wklejaj.pl Wszelkie prawa zastrzeżone.