12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 | #include <algorithm>
#include <iostream>
bool is_ascii_digit(int ascii) {
if (ascii < (int)'0' || ascii > (int)'9') {
return false;
}
return true;
}
bool are_digits_strictly_increasing(int number) {
auto previousDigit = number % 10;
number /= 10;
while (number > 0) {
auto nextDigit = number % 10;
if (nextDigit > previousDigit) {
return false;
}
previousDigit = nextDigit;
number /= 10;
}
return true;
}
int fun(int* arr, int arrLength, bool (**tests)(int), int testsLength) {
int results[testsLength];
std::fill(results, results + testsLength, 0);
for (auto i = 0; i < arrLength; i++) {
for (auto j = 0; j < testsLength; j++) {
results[j] += (int)tests[j](arr[i]);
}
}
auto biggest = 0;
for (auto j = 0; j < testsLength; j++) {
if (results[j] > results[biggest]) {
biggest = j;
}
}
return biggest;
}
int main() {
const auto arrLength = 10;
int arr[arrLength] = {12, 34, 56, 48, 23, 55, 57, 45, 52, -235};
const auto farrLength = 2;
bool (*farr[farrLength])(int) = {is_ascii_digit,
are_digits_strictly_increasing};
const auto sarrLength = 2;
char* sarr[sarrLength] = {"is_ascii_digit", "are_digits_strictly_increasing"};
auto index = fun(arr, arrLength, farr, farrLength);
std::cout << sarr[index] << std::endl;
}
|