Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cctype>
  3. #include <iostream>
  4. #include <string>
  5.  
  6. int main(int argc, char ** argv) {
  7.     std::for_each(argv + 1, argv + argc, [](char * text) {
  8.         std::string input{text};
  9.         auto const b = std::begin(input);
  10.         auto const it = std::stable_partition(b, std::end(input),
  11.                                               [](auto v) {
  12.                                                 return std::isalpha(v);
  13.                                               });
  14.         std::transform(b, it, b, [](auto v) {
  15.                                     return std::tolower(v);
  16.                                  });
  17.         auto const middle = std::next(b, std::distance(b, it)/2);
  18.         std::cout << text << " => ";
  19.         if(!std::equal(b, middle, std::make_reverse_iterator(it))) {
  20.             std::cout << "not ";
  21.         }
  22.         std::cout << " palindrome\n";
  23.     });
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement