Advertisement
chevengur

Вводный курс: основы C++ | Урок 2: Функция, вас вызывают!

Aug 30th, 2023 (edited)
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>                            //сильно усложнил
  5.                                                 //Algorithm Manacher palindrome
  6.  
  7. using namespace std;
  8.  
  9. void IsPalindrome(string str) {
  10.     vector<char>word;
  11.     vector<char>reverse_word;
  12.     for (const auto& s: str) {
  13.         word.push_back(s);
  14.         reverse_word.push_back(s);
  15.     }
  16.     reverse(reverse_word.begin(), reverse_word.end());
  17.  
  18.     if (word == reverse_word) {
  19.         std::cout << 1 << endl;
  20.     }
  21.     else {
  22.         std::cout << 0 << endl;
  23.     }
  24. }
  25.  
  26. int main() {
  27.     IsPalindrome("V");
  28.     IsPalindrome("ara"s);
  29.     IsPalindrome("deer"s);
  30.     IsPalindrome(""s);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement