U
so?
#include "stdlib.h"
template<
typename CHAR = char,
typename TRAITS = std::char_traits<CHAR>
>
struct case_insensitive_equal
{
typedef CHAR value_type;
typedef TRAITS traits_type;
explicit case_insensitive_equal(const std::locale& locale = std::locale())
: locale(locale)
{}
bool operator() (value_type lhs, value_type rhs) const
{
make_compareable(lhs, rhs);
return traits_type::eq(lhs, rhs);
}
private:
std::locale locale;
void make_compareable(value_type& lhs, value_type& rhs) const
{
if(is_upper(lhs))
make_lower(lhs);
if(is_upper(rhs))
make_lower(rhs);
}
bool is_upper(value_type value) const
{
return std::isupper(value, locale);
}
void make_lower(value_type& val) const
{
val = std::tolower(val, locale);
}
};
template<typename T>
T remove(const T& in, typename T::value_type to_remove)
{
typedef typename T::const_iterator iterator;
T out(in);
iterator end = std::remove(out.begin(), out.end(), to_remove);
out.erase(end, out.end());
return out;
}
template<typename T, typename F>
bool is_palindrom(const T& value, F& functor)
{
typedef typename T::const_iterator iterator;
iterator mid = value.begin();
std::advance(mid, value.size()/2);
return std::equal(value.begin(), mid, value.rbegin(), functor);
}
int main()
{
for(std::string in; std::getline(std::cin, in); )
{
// in = "Ein Neger mit Gazelle zagt im Regen nie";
in = remove(in, ' ');
case_insensitive_equal<std::string::value_type> comparer;
std::cout << std::boolalpha << is_palindrom(in, comparer) << std::endl;
}
}
stdlib.h included (wie der name schon vermuten lässt) sämtliche standard-header...
sollte hier nur iostream, algorithm, iterator, string und locale sein...
oder für c&p einfach alles:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cctype>
#include <cerrno>
#include <csignal>
#include <csetjmp>
#include <cfloat>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <strstream>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
bb