#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
bool Palindrome(const std::string& str)
{
std::string temp = str;
std::reverse(temp.begin(), temp.end());
return str == temp;
}
void Print(const std::vector<std::string>& vec)
for (const auto &val : vec)
std::cout << val << " ";
int main()
std::vector<std::string> palindromes;
std::string str;
std::cin >> str;
while (str != ".")
if (Palindrome(str))
palindromes.push_back(str);
Print(palindromes);
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
bool Palindrome(const std::string& str)
{
std::string temp = str;
std::reverse(temp.begin(), temp.end());
return str == temp;
}
void Print(const std::vector<std::string>& vec)
{
for (const auto &val : vec)
{
std::cout << val << " ";
}
}
int main()
{
std::vector<std::string> palindromes;
std::string str;
std::cin >> str;
while (str != ".")
{
if (Palindrome(str))
{
palindromes.push_back(str);
}
std::cin >> str;
}
Print(palindromes);
return 0;
}