🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #161

Re: C++ problem - help

#161
From: Homer Meyer
Date: Thu, 08 Apr 1999 00:00
20 lines
1414 bytes
Victor wrote in message <7eatvr$p1g$1@barcode.tesco.net>...
>I have been asked to design a project to determine whether a word is a
>palindrome or not (btw a plaindrome is a word that is the same backwards ie
>noon).


This is almost a one-liner in C++.  Some time back I posted a solution for
this very problem.  You can easily find it with a search on DejaNews (I
did).  Here it is below:

#include <string>
#include <algorithm>

bool palindrome( std::string &s ) {
  return std::equal( s.begin(), s.begin + s.size()/2, s.rbegin() );
}

This function is case-sensitive, but it is fairly simple to make it
case-insensitive.  I leave that as an excercise.  (Hint:  use the version of
std::equal() that takes a predicate)
Technical Details
Message-ID: <7eirf3$gvq$1@news-2.csn.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7eatvr$p1g$1@barcode.tesco.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,61f8664269971e91
X-Google-Attributes: gid109fba,public
X-Google-Thread: 10d4ba,61f8664269971e91
X-Google-Attributes: gid10d4ba,public
X-Google-Thread: 114592,61f8664269971e91
X-Google-Attributes: gid114592,public
From: "Homer Meyer" <homer@cqg.com>
Subject: Re: C++ problem - help
Date: 1999/04/08
Message-ID: <7eirf3$gvq$1@news-2.csn.net>
X-Deja-AN: 464117233
References: <7eatvr$p1g$1@barcode.tesco.net>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Organization: Qwest Communications +1.303.226.6500 Denver Colorado
Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++