C/C++

Палиндром c++ Написать программу. Help!

Написать программу, которая проверяет, является ли введенное предложение (строка) палиндромом, без учета пробелов.
#include <algorithm>
#include <iostream>
#include <string>
#include <regex>
#include <locale>
using namespace std;
class Lowercase {
public:
Lowercase(const locale& loc) : loc_(loc) {}
char operator()(const char& ch) {
return tolower(ch, loc_);
}
private:
locale loc_;
};
bool palindrome(string str) {
str = regex_replace(str, regex(" +"), "");
locale loc("Russian_Russia.1251");
transform(str.begin(), str.end(), str.begin(), Lowercase(loc));
return str.compare(string(str.crbegin(), str.crend())) == 0;
}
void puts(const string& str) {
cout << str << '\n';
}
int main() {
system("chcp 1251 > nul");
string line;
getline(cin, line);
puts(palindrome(line) ? "Палинодром" : "Не палиндром");
system("pause > nul");
}
Nurymbet Berdikozhaev
Nurymbet Berdikozhaev
68 940
Лучший ответ
Илья Лейфер когда платят за количество строк ))
#include iostream
using namespace std;
bool IsPalindrom(string word)
{
    int i;

    i = 0;
    while (i < word.size() / 2)
    {
        if (word[i] != word[word.size() - i - 1])
            return (false);
        i++;
    }
    return (true);
}

int main() {
cout << ((IsPalindrom("abcsba")) ? "yes" : "no") << endl;

return 0;
}
23+32=55
42+24=66
54+45=99
21+12=33
Вуоля.

#include <iostream //последний знак убираю, а то mail удаляет все слово
#include <string
#include <cstring

int main()
{
std::string smth;
std::cout << "Insert word? ";
getline (std::cin, smth);
bool palindrome = true;

int length = smth.length();
for(int i=0;i < length ;i++)
{
if(smth[i] != smth[length-i-1])
{
palindrome = false;
break;
}
}

std::cout << "palindrome = " << std::boolalpha << palindrome << "!\n";
}
БB
Батик Best Boy
4 769
Дмитрий Важов А какие библиотеки подключать?
Батик Best Boy ну вон же сверху написаны через include три штуки