48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#include <boost/algorithm/is_palindrome.hpp>
|
|
#include <iostream>
|
|
#include <numeric>
|
|
#include <vector>
|
|
|
|
int main() {
|
|
std::cout << "Hello, World!" << std::endl;
|
|
|
|
std::vector<int> numbers = {1, 2, -1, 3, -2, 4};
|
|
|
|
numbers.erase(std::remove_if(
|
|
numbers.begin(),
|
|
numbers.end(),
|
|
[](int x) { return x < 0; }),
|
|
numbers.end());
|
|
|
|
auto sum = 0;
|
|
for (auto it = numbers.begin(); it != numbers.end(); it++) {
|
|
sum += *it;
|
|
}
|
|
|
|
std::cout << "Sum is: " << sum << "." << std::endl;
|
|
|
|
auto res = std::accumulate(
|
|
numbers.begin(),
|
|
numbers.end(),
|
|
1,
|
|
[](int a, int b) { return a * b; });
|
|
|
|
std::cout << "Multiplication is: " << res << "." << std::endl;
|
|
|
|
std::vector<int> palindrome_vec = {1, 2, 3, 2, 1};
|
|
|
|
if (boost::algorithm::is_palindrome(numbers)) {
|
|
std::cout << "Vec 1 is palindrome" << std::endl;
|
|
} else {
|
|
std::cout << "Vec 1 is not palindrome" << std::endl;
|
|
}
|
|
|
|
if (boost::algorithm::is_palindrome(palindrome_vec)) {
|
|
std::cout << "Vec 2 is palindrome" << std::endl;
|
|
} else {
|
|
std::cout << "Vec 2 is not palindrome" << std::endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|