需要创建一个程序,用户可以输入一个单词,反转该单词,并使用链接列表检查该单词是否为回文单词。在程序结束时,它将列出输入单词中的所有回文单词。
程序必须包括以下方法/功能:
a) menu() – as interface for the user
b) add_word(string) – to enter the word to the list
c) show_list() – to display the lists
d) reverse_word(string) – to reversed the word
e) palindrome(string) – to check if the word is palindrome
f) palindrome_list() – to list all of the palindrome words
g) delete_list() – to delete list
Example, segment of output:
How many words you want to enter: 3
Please enter a word: kayak
Please enter a word: madam
Please enter a word: world
Reversed the word: kayak
Reversed the word: madam
Reversed the word: dlrow
kayak, is a palindrome word.
madam, is a palindrome word
world, is not a palindrome word.
List of the palindrome words: kayak, madam
Declaration node and functions:
//declaration of node
struct Node{
string p_word;
Node *plink;
};
void menu();
void add_word(string);
void show_list();
void reversed_word(string);
void palindrome(string);
void palindrome_list();
void delete_list()
#include <iostream>
#include <cstring>
using namespace std;
int main(){
const int n=501;
char a[n];
int len,s=0,c=0,k=0;
cin.getline(a,n);
len=strlen(a);
for(int i=0;i<len;i++){
if(a[i]==' '||i==len-1){
c++;
if(i==len-1) k=i;
else k=i-1;
for(int j=k;j>=s;j--) cout<<a[j];
if(c==1){
cout<<" ";
c=0;
}
s=i+1;
}
}
cout<<endl;
return 0;
}