Palindrom
- 
					
					
					
					
 KasF schrieb: pumuckl schrieb: ist kürzer  string(a.rbegin(),a.rend()) == a ist kürzer  Vom Schreibaufwand vielleicht, aber nicht von der Laufzeit (davon, daß du noch zusätzlichen Speicher benötigst, will ich gar nicht reden)  
 
- 
					
					
					
					
 bool istPalindrom(const string &s) { return equal(s.begin(), s.begin()+s.size()/2, s.rbegin()); }
 
- 
					
					
					
					
 Mal nebenbei ... was ist den bitteschön Senfkunde? 
 
- 
					
					
					
					
 GreyHound schrieb: Mal nebenbei ... was ist den bitteschön Senfkunde? Wie kommst du jetz darauf???      
 
- 
					
					
					
					
 Es gibt ein Institut für Palindromistik und Senfkunde. Dort wird es näher beschrieben: Die Abteilung Senfkunde testet Senfsorten aller art auf ihre Eigenschaften und untersucht insbesondere die Wirkung von Senf auf das palindromische Zentrum im Kleinhirn. 
 
- 
					
					
					
					
 Oo Kannte den Begriff Palindrom garnicht  #include <iostream> #include <string> #include <algorithm> bool is_palindrome(const std::string&); int main() { std::cout << "======== Parlindrom V1.0 ========\nWort: " << std::flush; std::string input_word; std::cin >> input_word; // oder halt std::getline(std::cin, input_word) wenn du auch Leerzeichen erlauben willst. std::cout << "Das angegebene Wort ist " << (is_parlindrome() ? "" : "k") << "ein Parlindrom!" << std::endl; } bool is_palindrome(const std::string& str) { return std::equal(str.begin(), str.begin() + (str.length() / 2), str.rbegin()); }... 
 
- 
					
					
					
					
 danke für eure antowrten. auch wenn ich ein paar davon von der logik her noch nicht nachvollziehen konnte. 
 aber ich denk mir mal das das noch kommen wird. 
 
- 
					
					
					
					
 / GIP Praktikum 12 (Palindrome) #include <iostream> 
 #include <string>
 #include <cctype>using namespace std; int main () { 
 string vonvorne, vonhinten;
 bool x = 0;
 do
 {
 x = 0;
 cout << "Text = ";
 cin >> vonvorne; // String wird eingelesen
 for (int i=0; vonvorne[i]!='\0'; i++) // Auf Nullterminierungszeichen prüfen
 {
 vonvorne[i]=toupper(vonvorne[i]); // In Grossbuchstaben umwandeln
 }
 for (int i=0; vonvorne[i] !='\0'; i++) // Auf Nullterminierungszeichen prüfen
 {
 if (!(vonvorne[i]<='Z' && vonvorne[i] >= 'A')) //Überprüfung ob ein Zeichenvorhanden ist oder das Zeichen ein Element des Alphabets ist!
 {
 x = 1;
 }
 if (x==1)
 {
 break;
 }
 }
 }while (x==1);for(int i=0; vonvorne[i]!='\0'; i++) 
 {
 vonhinten = vonvorne[i] + vonhinten; ///??? WAS PASSIERT HIER GENAU???
 if (vonvorne[i+1] == '\0')
 {
 vonhinten[i+1] = '\0';
 }
 }if (vonvorne == vonhinten) 
 {
 cout << " Das Wort ist ein Palindrom! \n \n";
 }else 
 {
 cout << " Das wort ist KEIN Palindrom \n \n";
 }
 return 0;
 }-------------------------------- 
 --------------------------------for(int i=0; vonvorne[i]!='\0'; i++) 
 {
 vonhinten = vonvorne[i] + vonhinten; ///??? WAS PASSIERT HIER GENAU???
 if (vonvorne[i+1] == '\0')
 {
 vonhinten[i+1] = '\0';
 }
 }------------------------------- 
 -------------------------------Könnte mir das mal jemand mit Worten erläutern!? Erst kommt ja wieder die Überprüfung aufs Nullterminierungszeichen... 
 dann wird das Zeichen von vonvorne[i] + vonhinten genommen... wieso wird vonhinten z.B. vorher nicht 0 gesetzt?!?!?!
 Addiert der da nur noch die Zeichen?! und Feierabend?!Danke 
 Gruss
 
- 
					
					
					
					
 Und um es spannender zu machen sollte bei Palindromen darauf geachtet werden, das: 
 - Leerzeichen ignoriert werden
 - Großbuchstaben ignoriert werdenDann gilt auch folgendes (wenn auch politisch nicht unbedingt korrekt) als Palindrom: 
 "Ein Neger mit Gazelle zagt im Regen nie"Nur um die Aufgabe mal interessanter zu machen.  
 
- 
					
					
					
					
 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.hincluded (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