AI编程助手
AI免费问答

在C程序中,将句子中最长的回文单词打印出来

WBOY   2023-09-04 22:57   755浏览 转载

在c程序中,将句子中最长的回文单词打印出来

给定一个句子,挑战是从给定的句子中找到最长的回文

什么是回文?

回文是一个单词或序列,即使在之后其含义仍然保持不变反转字符串

示例 - Nitin,反转字符串后其含义保持不变。

挑战是从给定的句子中找到最长的回文。

喜欢的句子是:malayalam liemadameil iji

它包含三个回文词,但最长的是 - liemadameil

算法

START
STEP 1 -> Declare start variables I, j, k, l, max to 0, index to -1, check to 0, count to 0
Step 2 -> Loop For i to 0 and i<strlen and i max="0," k="i" j="i+1" while str increment by l="j-1" loop if count set index="i" end else step> End Loop For
Step 4 -> Loop For i = index and i!=-1 && str[i]!=' ' && str[i]!='\0' and i++
   Print str[i]
Step 5 -> End Loop For
STOP</strlen>

示例

#include <stdio.h>
#include <string.h>
int main(int argc, char const *argv[]) {
   char str[] = {"malayalam liemadameil iji"};
   int i, k, l, j, max =0, index = -1, check = 0, count = 0;
   for(i=0; i<strlen i max="0;" k="i;" j="i+1;" while str l="j-1;" if index="i;" count="max;" else l-- printf><h2>输出</h2>
<p>如果我们运行上面的程序,它将生成以下输出。</p>
<pre class="brush:php;toolbar:false;">liemadameil
声明:本文转载于:tutorialspoint,如有侵犯,请联系admin@php.cn删除