提着裤子去拉屎 2021-12-31 11:30 采纳率: 77.8%
浏览 51
已结题

求解,怎么反转一个单词,需要包括以下的方法。需按要求

需要创建一个程序,用户可以输入一个单词,反转该单词,并使用链接列表检查该单词是否为回文单词。在程序结束时,它将列出输入单词中的所有回文单词。
程序必须包括以下方法/功能:
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()

  • 写回答

1条回答 默认 最新

  • 神仙别闹 2021-12-31 11:34
    关注
    #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;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 1月8日
  • 已采纳回答 12月31日
  • 修改了问题 12月31日
  • 修改了问题 12月31日
  • 展开全部