98-6(栈-回文的使用)
来源:互联网 发布:轻淘客cms模板 编辑:程序博客网 时间:2024/05/09 19:20
#include <iostream>#include <stdlib.h>#include <stdbool.h>using namespace std;typedef struct node{ char c; struct node* pnext;}qnode,*pnode;typedef struct stack{ pnode top; pnode botton;}qstack,*pstack;void init(pstack s){ s->top=(pnode)malloc(sizeof(qnode)); s->botton=s->top;}bool empty(pstack s){ if(s->top==s->botton) return true; else return false;}void push(pstack s,char c_){ pnode q; q=(pnode)malloc(sizeof(qnode)); q->c=c_; q->pnext=s->top; s->top=q;}char gettop(pstack s){ return s->top->c;}void pop(pstack s){ pnode q; if(empty(s)) cout<<"出栈失败"; else { q=s->top; s->top=q->pnext; free(q); } }int lengh(pstack s){ int i; pnode q=s->top; if(q==s->botton) i=0; return i;}void judge(char a[],int i,int &lengh_){ stack s; init(&s); int j; char k; for(j=0;j<(i/2);j++) { push(&s,a[j]); } if(i%2==0)//如果是双数,则从i%2开始于栈顶比较 j=i/2; else j=i/2+1;//如果是单数,则从i%2+1开始比较 for(;j<i;j++) { k=gettop(&s); if(a[j]==k) { pop(&s); } } lengh_=lengh(&s);}int main(){ int i=0,l; char ch; char a[100]; while((ch=getchar())!='\n') { a[i]=ch; i++; } judge(a,i,l); if(l==0) {cout<<"yes"; } else { cout<<"no"; } }
0 0
- 98-6(栈-回文的使用)
- 判断回文字符序列-栈的使用
- 使用栈判断回文
- 【算法】回文数的判断--栈的使用
- 链栈的学习(回文数)
- 栈(回文数)
- 第十一周项目 6 回文,素数(1000以内的回文数)
- 第十一周项目 6 回文,素数(1000以内的回文素数)
- leetcode之回文字串库函数的使用
- 回文的java实现(栈和队列的配合)
- 回文质数问题(用生成回文数的方法)
- 使用栈来检测回文字符串
- 例3.4 使用栈判断回文
- C++ 使用栈判断回文字符串
- 使用栈与队列判断回文串
- 第十一周项目 6 回文,素数(回文数)
- 第十一周项目6-回文、素数(判断回文数)
- 第十一周项目6回文、素数(二)回文数
- 指针
- 题目1112:拦截导弹 最长递增子序列(LIS)
- 题目1131:合唱队形
- 题目1042:Coincidence(最长公共子序列)
- 题目1452:搬寝室
- 98-6(栈-回文的使用)
- Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
- # ffmpeg 将多幅图片压缩成视频 h264 avi
- C/C++ 学习笔记:类相关
- 2017网易内推笔试题---混合颜料
- 录制手机屏幕并且上传到博客的方法
- leetcode_c++:图:Minimum Height Trees(310)
- Kafka简介及其主要组件
- 自定义View之饼状图