Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this simple coding activity. I will award full points to the fi

ID: 643526 • Letter: I

Question

I need help with this simple coding activity. I will award full points to the first person whos code works. I would appreciate it if you included a small explanation of what it is you're doing so that I can understand.

I need help with this simple coding activity. I will award full points to the first person whos code works. I would appreciate it if you included a small explanation of what it is you're doing so that I can understand. Keep asking the user For characters until the user enters #. The characters may be stored in a vector of chars or in a string. Do NOT include # in your list. IF the series of characters is a palindrome, print out Yes!. lithe series of characters is NOT a palindrome, printout No! A palindrome is a word that can be read Forwards and backwards the same. And example of a palindromes is racecar.

Explanation / Answer

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
   char a[1000];//to store the string
   char temp[2];//to read the characters one by one
   int i = 0;
   while (1)
   {
       scanf("%s", temp);//reading characters
       if (temp[0] == '#')//if character is '#' the stop reading
           break;
       else//else keep reading
       {
           a[i] = temp[0];
           i++;
       }
   }
   a[i] = '';//marking the end of string
   int len = strlen(a);//length of string
   int x = 0, y = len - 1;//x points to beginning of string and y points to end initially
   bool p = true;//assuming initially the string is palindrome
   while (x < y)//inspection until midpoint of string is reached
   {
       if (a[x] != a[y])//string is not palindrome
       {
           p = false;
           break;//break out of loop
       }
       else//else keep on inspecting
       {
           x++; y--;
       }
   }
   if (p)
       printf("Yes! ");
   else
       printf("No! ");
}