本文介绍了确定字符串是否是回文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好专家,


我写一个名为palindrome的函数来确定一个字符串

是否是回文,并用一些示例字符串测试它。将它作为小工具函数添加到公司/项目库是否合适



根据其质量?我将很高兴从你的每个方面得到你的建议

:界面设计,C语言知识或

算法高效。


此致,


lovecreatesbeauty

/ *文件名:palindrome.c

*功能:bool回文(char * s );

*描述:确定字符串是否是回文

*日期:2006年5月8日

* /


#include< stdbool.h>

#include< stddef.h>

#include< string.h>


bool palindrome(char * s)

{

bool palindromic = true;

size_t len = strlen (s);


if(len> 1)

{

for(unsigned i = 0; i< len / 2; ++ i)

{

if(s [i]!= s [len - 1 - i])

{

palindromic = false;

休息;

}

}

}


返回回文;

}

/ * test * /

#include< stdio.h>


int main()

{

printf("%i \ n",palindrome(" deed)));

printf("%i \ n",palindrome(" deeds)) );

}


/ *

$ gcc -W -Wall -std = c99 -pedantic palindrome.c

$ ./a.out

1

0

$

* /

Hello experts,

I write a function named palindrome to determine if a character string
is palindromic, and test it with some example strings. Is it suitable
to add it to a company/project library as a small tool function
according to its quality? I will be very happy to get your suggestion
from every aspect on it: interface design, C language knowledge or
algorithm efficient.

Sincerely,

lovecreatesbeauty
/* Filename : palindrome.c
* Function : bool palindrome(char *s);
* Description: to determine if a character string is palindromic
* Date : 8 May 2006
*/

#include <stdbool.h>
#include <stddef.h>
#include <string.h>

bool palindrome(char *s)
{
bool palindromic = true;
size_t len = strlen(s);

if (len > 1)
{
for (unsigned i = 0; i < len / 2; ++i)
{
if (s[i] != s[len - 1 - i])
{
palindromic = false;
break;
}
}
}

return palindromic;
}
/* test */
#include <stdio.h>

int main()
{
printf("%i\n", palindrome("deed"));
printf("%i\n", palindrome("deeds"));
}

/*
$ gcc -W -Wall -std=c99 -pedantic palindrome.c
$ ./a.out
1
0
$
*/

推荐答案




这篇关于确定字符串是否是回文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 11:55