当前位置:网站首页>习题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;
}
边栏推荐
猜你喜欢

The device is in use when win10 ejects USB

FastAPI 5 - 常用请求及 postman、curl 使用(parameters,x-www-form-urlencoded, raw)

Tkinter学习笔记(四)

高考结束,人生才刚刚开始,10年职场老鸟给的建议

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

Basic operation of graph (C language)

Matplotlib和tkinter学习笔记(一)
![[Yu Yue education] Yancheng Normal University Advanced Algebra reference](/img/3f/cd7f6f420fb1d453acca9aa73665ba.jpg)
[Yu Yue education] Yancheng Normal University Advanced Algebra reference

Top - K problem

Internet of things development practice 18 scenario linkage: how does an intelligent light perceive light? (I) (learning notes)
随机推荐
Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.4
On the night of the joint commissioning, I beat up my colleagues
One question per day -- verifying palindrome string
向线程池提交任务
超标量处理器设计 姚永斌 第2章 Cache --2.2 小节摘录
Glory earbud 3 Pro with three global first strong breakdowns flagship earphone Market
每日一题-1317. 将整数转换为两个无零整数的和
3.2 测试类的命名规则
6.项目上线
机器学习之Logistic回归简单实例
Unity3d getlaunchintintforpackage getting package returned null
Maze problem in C language
Why microservices are needed
3.3 测试模块的命名规则
高考结束,人生才刚刚开始,10年职场老鸟给的建议
The college entrance examination is over, and life has just begun. Suggestions from a 10-year veteran in the workplace
Prefabricated dishes in the trillion market have also begun to roll inside. How can brands stand out in the fierce competition?
[Yu Yue education] Yancheng Normal University Advanced Algebra reference
揭秘爆款的小程序,为何一黑到底
SequenceList顺序表的实现