awdawdawdawdgwag

Kolorwanie:
Status:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
#include <iostream>

using namespace std;

int get_last(int a) {
    while(a > 9) {
        a = a % 10;
    }
    return a;
}

int get_first(int a) {
    while (a >= 10) {
        a = a / 10;
    }
    return a;
}

bool have_some_border_digits(unsigned int *tab, int size) {
    for (int i = 1; i < size; i++) {
        if (get_last(tab[i-1]) != get_first(tab[i])) {
            return false;
        }
    }
    return true;
}

unsigned int* fun(unsigned int *tab, int size, bool (*fun2)(unsigned int *, int), int &a) {
    
    int begindex = 0;
    int index = 1;
    int sizet = 0;
    int maxsize = 0;
    int maxbegindex;
    while (index < size-1) {
        if(fun2(tab + begindex, index - begindex+1)) {
            sizet = index - begindex;
            if(sizet > maxsize) {
                maxsize = sizet;
                maxbegindex = begindex;
            }
            index++;
        } else {
            begindex = index;
            index++;
            sizet = 0;
        }
    }
    cout << "maxs = " << maxsize << endl;
    a = maxsize;
    return &tab[maxbegindex];
}

int main() {
    unsigned int tab[10] = { 12, 24, 45, 54, 58, 86, 64, 41, 14, 48 };
    int a = 0;
    unsigned int* b = fun(tab, 10, have_some_border_digits, a);
    
    for (int i = 0; i < a+1; i++)
    {
        cout << *(b + i) << " ";
    }
    
}

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