mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-12-16 15:44:39 +00:00
60 lines
981 B
Markdown
60 lines
981 B
Markdown
|
# 6-6 判断回文字符串
|
|||
|
|
|||
|
本题要求编写函数,判断给定的一串字符是否为“回文”。所谓“回文”是指顺读和倒读都一样的字符串。如“XYZYX”和“xyzzyx”都是回文。
|
|||
|
|
|||
|
### 函数接口定义:
|
|||
|
```c++
|
|||
|
bool palindrome( char *s );
|
|||
|
```
|
|||
|
函数`palindrome`判断输入字符串`char *s`是否为回文。若是则返回`true`,否则返回`false`。
|
|||
|
|
|||
|
### 裁判测试程序样例:
|
|||
|
```c++
|
|||
|
#include <stdio.h>
|
|||
|
#include <string.h>
|
|||
|
|
|||
|
#define MAXN 20
|
|||
|
typedef enum {false, true} bool;
|
|||
|
|
|||
|
bool palindrome( char *s );
|
|||
|
|
|||
|
int main()
|
|||
|
{
|
|||
|
char s[MAXN];
|
|||
|
|
|||
|
scanf("%s", s);
|
|||
|
if ( palindrome(s)==true )
|
|||
|
printf("Yes\n");
|
|||
|
else
|
|||
|
printf("No\n");
|
|||
|
printf("%s\n", s);
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
/* 你的代码将被嵌在这里 */
|
|||
|
```
|
|||
|
|
|||
|
### 输入样例1:
|
|||
|
```in
|
|||
|
thisistrueurtsisiht
|
|||
|
```
|
|||
|
|
|||
|
### 输出样例1:
|
|||
|
```out
|
|||
|
Yes
|
|||
|
thisistrueurtsisiht
|
|||
|
|
|||
|
```
|
|||
|
|
|||
|
### 输入样例2:
|
|||
|
```
|
|||
|
thisisnottrue
|
|||
|
```
|
|||
|
|
|||
|
### 输出样例2:
|
|||
|
```
|
|||
|
No
|
|||
|
thisisnottrue
|
|||
|
```
|