(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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:(C语言)栈实现队列元素逆置-洋葱先生-杨少通
下一篇:(C语言)十进制转换成R进制-洋葱先生-杨少通

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年03月27日 02时53分02秒