i'm trying to enter a string phrase and store its last word in an Array,
if the word is palindrom then a message will showit

Recommended Answers

All 3 Replies

Please post some code and ask a more specific question with a problem you are having with YOUR code.

Member Avatar for dany4ev_1

mahabelg you can do following but do give a try first:

try to split and store the read input into an array or list, i believe you want to get that via console to give a hint here is some example:

var input = Console.ReadLine();
string [] arr = new string[] { };
if(input.Length > 1) {
    for(int ind=0; ind < input.Length-1; ind++) {
        arr[ind] = input.split(' ')[ind];
     }
}

next when you do have the inputs in your array meaning at this point you could have something like:

arr[0] contains "inputstring1"
arr[1] contains "inputstring2"

you can start to check for palindromes write a separate method why won't you!! check after reversing the individual input strings and if their reversed version is equal to the original version the one which you extracted in the array as described just above you can confirm whether read string was a palindrome or otherwise!!

Happy coding !! :)

Member Avatar for iamthwee
#include <iostream>
#include <string>

using namespace std;

int main()
{

    string phrase;
    cin>>phrase;

    if (phrase == "palindrome")
    {
        cout << "showit";

    }
    else
    {
        cout <<"nope";
    }

    return 0;

}

Couldn't resist.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.