当前位置:网站首页>习题8-8 判断回文字符串 (20 分)
习题8-8 判断回文字符串 (20 分)
2022-06-11 22:18:00 【小言同学Y】
本题要求编写函数,判断给定的一串字符是否为“回文”。所谓“回文”是指顺读和倒读都一样的字符串。如“XYZYX”和“xyzzyx”都是回文。
函数接口定义:
bool palindrome( char *s );
函数palindrome判断输入字符串char *s是否为回文。若是则返回true,否则返回false。
裁判测试程序样例:
#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:
thisistrueurtsisiht
输出样例1:
Yes
thisistrueurtsisiht
输入样例2:
thisisnottrue
输出样例2:
No
thisisnottrue
bool palindrome( char *s ){
int i,j;
for(i=0,j=strlen(s)-1;i<j;i++,j--){
if(s[i]!=s[j])
return false;
}
return true;
}
边栏推荐
- 揭秘爆款的小程序,为何一黑到底
- [Yu Yue education] General English of Shenyang Institute of Engineering (4) reference materials
- NLP - fastText
- 【Uniapp 原生插件】商米钱箱插件
- 电脑强制关机 oracle登录不上
- Matlab: solution of folder locking problem
- inner join执行计划变了
- Conception du Processeur superscalaire Yao yongbin chapitre 2 cache - - sous - section 2.4 extrait
- C language implements eight sorts (3)
- Custom implementation offsetof
猜你喜欢

Basic operation of graph (C language)

Win10弹出USB时出现该设备正在使用的解决方法

Top - K problem

移动端——swipe特效之图片时间轴

How to view computer graphics card information in win11

超標量處理器設計 姚永斌 第2章 Cache --2.4 小節摘錄

C language to achieve eight sorts (2)

仅需三步学会使用低代码ThingJS与森数据DIX数据对接

What is deadlock? (explain the deadlock to everyone and know what it is, why it is used and how to use it)

The device is in use when win10 ejects USB
随机推荐
Non recursive writing of quick sort
Nmap performs analysis of all network segment IP survivals in host detection
Unity中使用调用Shell的命令行
Addition without addition, subtraction, multiplication, Division
带有 ceph-csi 的静态 PVC
Win10弹出USB时出现该设备正在使用的解决方法
win10字体模糊怎么调节
Analysis of the implementation principle of an open source markdown to rich text editor
206. reverse linked list
Basic operation and question type summary of binary tree
Use the securecrtportable script function to read data from network devices
If I take the college entrance examination again, I will study mathematics well!
Matlab: solution of folder locking problem
3.2 测试类的命名规则
win11怎么看电脑显卡信息
R7-1 列表或元组的数字元素求和
Are you still using localstorage directly? It's time to raise the bar
【NodeJs】Electron安装
[data mining time series analysis] restaurant sales forecast
【数据挖掘时间序列分析】餐厅销量预测