Napisz funkcję, która sprawdzi, czy podany tekst jest palindromem. Funkcja powinna zwracać wartość true lub false (funkcja nie powinna tworzyć napisu odwrotnego). W języku c++

Napisz funkcję, która zwróci maksymalną możliwą liczbę ułożoną z cyfr liczby przekazanej jako argument (argument jest typu int) np. dla: 232532 wynik: 533222 dla: 1234499 wynik: 9944321 w języku c++

Napisz funkcję, która jako argument otrzymuje tablicę liczb typu int złożoną z cyfr, oraz liczbę określającą rozmiar tablicy. Funkcja powinna zwracać najdłuższy podciąg składający się z samych zer. np. dla: 123003000333053309930000 wynik: 4 w języku c++
Z góry bardzo dziękuje, potrzebuje na jutro.



Odpowiedź :

REGNAD

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