Odpowiedź :
Odpowiedź:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
bool isPalindrome(const std::string &s) {
return std::equal(s.begin(), s.begin() + s.length() / 2, s.rbegin());
}
int maxNumber(int number) {
std::vector<int> digits;
while (number > 0) {
digits.push_back(number % 10);
number /= 10;
}
std::sort(digits.begin(), digits.end());
int maxi = 0;
int counter = 1;
for (const int digit: digits) {
maxi += counter * digit;
counter *= 10;
}
return maxi;
}
int maxSubsequence(const int tab[], int n) {
int maxi = 0;
int counter = 0;
for (int i = 0; i < n; i++) {
if (tab[i] == 0) {
counter++;
} else {
maxi = std::max(counter, maxi);
counter = 0;
}
if (i == n - 1) {
maxi = std::max(counter, maxi);
counter = 0;
}
}
return maxi;
}
int main() {
std::cout << std::boolalpha << isPalindrome("mama") << std::endl;
std::cout << maxNumber(232532) << std::endl;
int tab[] = {1, 2, 3, 0, 0, 3, 0, 0, 0, 3, 3, 3, 0, 5, 3, 3, 0, 9, 9, 3, 0, 0, 0, 0};
int n = sizeof(tab) / sizeof(tab[0]);
std::cout << maxSubsequence(tab, n);
return 0;
}
Wyjaśnienie:
Zajęło mi to zdecydowanie zbyt dużo czasu, także jak dasz naj to będzie miło xd