(C语言)判断字符串是否中心对称-洋葱先生-杨少通
发布日期:2021-10-03 07:58:42
浏览次数:2
分类:技术文章
本文共 1702 字,大约阅读时间需要 5 分钟。
注:本程序由Visual Studio 2015编写,与VC++6.0稍有区别,复制到VC++6.0注释掉“#include “stdafx.h””即可运行,复制到VS可直接运行。
#include "stdafx.h"#include#include #include using namespace std;#define OK 1#define ERROR 0#define OVERFLOW -1#define UNDERFLOW -2#define STACK_INIT_SIZE 80#define STACKINCREMENT 10typedef int status;//typedef ElemType char;#define ElemType chartypedef struct { ElemType *base; ElemType *top; int stacksize;}SqStack;SqStack S;status InitStack(SqStack &S){ S.base = (ElemType*)malloc(STACK_INIT_SIZE * sizeof(ElemType)); if (!S.base)exit(OVERFLOW); S.top = S.base; S.stacksize = STACK_INIT_SIZE; return OK;}status Push(SqStack &S, ElemType e) { if (S.top-S.base == S.stacksize) { S.base = (ElemType*)realloc(S.base, (S.stacksize + STACKINCREMENT) * sizeof(ElemType)); if (!S.base)exit(OVERFLOW); S.top = S.base + S.stacksize; S.stacksize += STACKINCREMENT; } *S.top++ = e; return OK;}status Pop(SqStack &S, ElemType &e) { if (S.top == S.base)exit(UNDERFLOW); e = *(S.top=S.top-1); return OK;}int main() { char str[30] = ""; ElemType e; cout << "\t\t\t\t*\t\t\t\t\t*"; cout << endl << "\t\t\t\t*\t计科1512-02210151232-杨少通\t*" << endl; cout << "\t\t\t\t*****************************************" << endl << endl; cout << "****************栈逆置队列元素****************" << endl << endl; cout << "请输入字符串:"; cin >> str; for (int i = 0; i < strlen(str); i++) Push(S, str[i]); for (int j = 0; j < strlen(str); j++) { Pop(S, e); if (str[j] != e) { cout << "“"< <<"”不是中心对称的字符串!" << endl; return 0; } } cout << "“" << str << "”是中心对称的字符串!" << endl; return 0;}
如有转载请注明来源: www.dreamload.cn/blog/?p=246&preview=true (洋葱先生)
转载地址:https://blog.csdn.net/Kindergarten_Sir/article/details/108587464 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2024年03月27日 02时53分02秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
程序员过劳晕倒 | 到底是谁剥夺了我们下班的权利?
2019-04-25
Google 开发者大会申请结果出来啦
2019-04-25
想认识比你厉害的人,你应该注意的几个细节
2019-04-25
你辛辛苦苦考的大学,就有资格让你去骚扰女生?
2019-04-25
微信更新,重点关注!
2019-04-25
这个小常识,竟然还有人不知道!
2019-04-25
对降准的一点看法
2019-04-25
你有「玻璃心」吗?
2019-04-25
解惑 | 一个接地气的提问!
2019-04-25
容易被忽略的陌生人社交礼仪!
2019-04-25
DbHelper
2019-04-25
SqlHelper
2019-04-25
ArticleDAL
2019-04-25
git 终端显示中文乱码
2019-04-25
关于java.lang.IllegalStateException: getOutputStream() has already been called for this response求解
2019-04-25
oracle 10.2.0.1.0 误删除数据文件 后的处理方法
2019-04-25
JPA 默认值配置
2019-04-25
myeclipse 的 maven工程报错或pom.xml头报错解决办法
2019-04-25
反向Ajax,第2部分:WebSocket
2019-04-25
反向Ajax,第1部分:Comet介绍
2019-04-25