🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: C++ problem - help

#145
From: Ever Olano
Date: Mon, 05 Apr 1999 00:00
44 lines
2304 bytes
Hello, Victor.  I'm sure others would propose solutions like using the STL
reverse() algorithm or using strrev() and then stricmp() but I will assume
that you are not allowed to use them yet.  I will work on what you currently
have.  Here is my proposed solution (Warning: untested!):

>int main(int argc, char **argv)
>{
>  int Front;
>  int Back;
>  bool Palindrome = true;        // use built-in boolean data type and
initialize it
                                                     // to true
>  AnsiString InputString;
>    InputString = ReadStringPr("Enter your non-empty string for testing");
>    Front = 0;                               // not 1
>    Back = Length(InputString) - 1  // without the minus one, you will be
                                                              // pointing to
the terminating null character,
                                                             // unless your
Length() function includes
                                                             // it in the
count.
>    while (Front < Back)
>      {
          // as soon as you find a pair that doesn't match,
          // then, you're sure it's not a palindrome
>        if (InputString[Front] != InputString[Back])
          {
>           Palindrome = false;
             break;
          }
>        ++Front;
>        --Back;
>      }
>    if (Palindrome)
>      WriteString("Yes, it is a palindrome");
>    else
>      WriteString("No it is not a palindrome");
>
>    getchar();
>    return 0;
>}

Ever
Technical Details
Message-ID: <37090520.0@newsread.exodus.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: 114592,61f8664269971e91
X-Google-Attributes: gid114592,public
X-Google-Thread: 10d4ba,61f8664269971e91
X-Google-Attributes: gid10d4ba,public
X-Google-Thread: 109fba,61f8664269971e91
X-Google-Attributes: gid109fba,public
From: "Ever Olano" <everao@my-dejanews.com>
Subject: Re: C++ problem - help
Date: 1999/04/05
Message-ID: <37090520.0@newsread.exodus.net>
X-Deja-AN: 462957692
X-NNTP-Posting-Host: nat-207-82-53-132.cybersource.com
References: <7eatvr$p1g$1@barcode.tesco.net>
Organization: news://newsread.exodus.net : Crossing the Invisible Line
Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3