当前位置: 首页 > news >正文

提供网站建设的公司百度搜索引擎网址格式

提供网站建设的公司,百度搜索引擎网址格式,广告投放工作怎么样,台州电子商务网站建设目录 1 问题背景 2 具体思路 3 代码实现 3.1 顺序栈实现 3.2 链栈实现 1 问题背景 栈的括号匹配问题是指在给定一个字符串(包含多种括号),判断其中的括号是否能够正确匹配,即每个左括号是否有一个对应的右括号与之匹配&#x…

目录

1 问题背景

2 具体思路

3 代码实现

3.1 顺序栈实现

3.2 链栈实现


1 问题背景

  栈的括号匹配问题是指在给定一个字符串(包含多种括号),判断其中的括号是否能够正确匹配,即每个左括号是否有一个对应的右括号与之匹配,并且左右括号必须以正确的顺序进行匹配。

例如,字符串"((()))"中的括号就能够正确匹配,而字符串"()())"中的括号就无法正确匹配。

 

2 具体思路

这是王道给出的流程图:

图1 王道给出的流程图

 

看起来有点吃力,我来总结一下,很简单,就几步:

  1. 遍历给定的字符串,对于每个字符进行判断。
  2. 如果字符是左括号,将其入栈。
  3. 如果字符是右括号,将其与栈顶元素作比较,判断该元素是否是与之匹配的左括号。如果是,弹出栈顶元素,并继续遍历;如果不是,说明括号不匹配,返回false。
  4. 如果字符串遍历完毕,栈为空,则说明全部括号匹配,返回true;否则,返回false。

注意如果在准备弹出元素时发现栈已为空,说明前面没有左括号与该右括号匹配,返回false。

3 代码实现

以Acwing上一道例题举例:3693. 括号匹配 - AcWing题库

输入格式

共一行,包含一个由 `<`,`(`,`{`,`[`,`>`,`)`,`}`,`]` 构成的字符串。

输出格式

如果输入的字符串中的括号正确匹配则输出 `yes`,否则输出 `no`。

数据范围

输入字符串长度不超过 10000。

输入样例:

    (){}

输出样例:

    yes

 

3.1 顺序栈实现

#include<stdio.h>
#include<string.h>
#include<stdbool.h>    //C语言引入该库才有bool值#define MAX_SIZE 100000  //定义栈中元素的最大个数typedef struct {int data[MAX_SIZE];  //静态数组存放栈中元素int top;    //栈顶指针
} SqStack;//初始化栈
void initStack(SqStack *s) {s->top = -1;
}//判断栈空
bool stackEmpty(SqStack s) {return s.top == -1;  //如果栈是空的,那么就会返回true
}//新元素入栈
bool push(SqStack *s, int x) {if (s->top == MAX_SIZE - 1) //如果栈已满,返回falsereturn false;s->data[++(s->top)] = x;  //否则先将栈顶指针的值加1,然后再使用增加后的栈顶指针指向的位置作为数组下标,将x存储到data数组中return true;
}//出栈
bool pop(SqStack *s, int *x) {if (s->top == -1) { //因为栈已空,再出栈报错返回falsereturn false;}*x = s->data[s->top--]; //从栈顶取出一个元素并赋值给x*,然后将栈顶指针减1,即把栈顶指针指向它下方的元素/*为什么给x*呢?因为需要通过指针参数才能把栈的元素值传递出去,进而传给topElem*/return true;
}//括号匹配算法的主体
bool bracketCheck(char str[]) {SqStack s;    initStack(&s);for (int i = 0; i < strlen(str); i++) {if (str[i] == '<' || str[i] == '(' || str[i] == '{' || str[i] == '[') {push(&s, str[i]);} else {if (stackEmpty(s)) {return false;}int topElem;  //topElem作为中间变量,记录从栈中弹出的栈顶元素if (!pop(&s, &topElem)) { //如果取出栈顶元素失败,说明栈为空,则匹配失败,返回falsereturn false;}if (str[i] == '>' && topElem != '<') {return false;}if (str[i] == ')' && topElem != '(') {return false;}if (str[i] == ']' && topElem != '[') {return false;}if (str[i] == '}' && topElem != '{') {return false;}}}return stackEmpty(s); //栈空,说明所有括号都能匹配成功,返回true;否则说明还有没配成功的括号,返回false
}int main() {char str[MAX_SIZE];  //接收字符串scanf("%s", str);if (bracketCheck(str)) printf("yes");else printf("no");return 0;
}

3.2 链栈实现

#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>typedef struct Node {int data;struct Node* next;
} Node;typedef struct {Node* top;int count;
} LinkedStack;// 初始化链栈
void InitStack(LinkedStack* S) {S->top = NULL;S->count = 0;
}// 判断栈空
bool StackEmpty(LinkedStack* S) {return S->count == 0;
}// 新元素入栈
bool Push(LinkedStack* S, int x) {Node* node = (Node*)malloc(sizeof(Node));if (node == NULL) {return false;  // 内存分配失败,入栈失败}node->data = x;node->next = S->top;S->top = node;S->count++;return true;
}// 弹出栈顶元素
bool Pop(LinkedStack* S, int* x) {if (StackEmpty(S)) {return false;  // 栈空,弹出失败}Node* node = S->top;S->top = node->next;*x = node->data;free(node);S->count--;return true;
}// 读取栈顶元素
bool GetTop(LinkedStack* S, int* x) {if (StackEmpty(S)) {return false;  // 栈空,读取失败}*x = S->top->data;return true;
}// 括号匹配检查
bool bracketCheck(char str[]) {LinkedStack S;InitStack(&S);for (int i = 0; i < strlen(str); i++) {if (str[i] == '<' || str[i] == '(' || str[i] == '{' || str[i] == '[') {Push(&S, str[i]);} else {if (StackEmpty(&S)) {return false;  // 栈空,匹配失败}int topElem;if (!Pop(&S, &topElem)) {return false;  // 弹出失败,匹配失败}if (str[i] == '>' && topElem != '<') {return false;  // 匹配失败}if (str[i] == ')' && topElem != '(') {return false;  // 匹配失败}if (str[i] == ']' && topElem != '[') {return false;  // 匹配失败}if (str[i] == '}' && topElem != '{') {return false;  // 匹配失败}}}return StackEmpty(&S);
}int main() {char str[100000];scanf("%s", str);if (bracketCheck(str)) {printf("yes\n");} else {printf("no\n");}return 0;
}

 


文章转载自:
http://dinncobiophilosophy.ydfr.cn
http://dinncoparacyesis.ydfr.cn
http://dinncomorningtide.ydfr.cn
http://dinncoarteritis.ydfr.cn
http://dinncoautotransplant.ydfr.cn
http://dinncomedievalist.ydfr.cn
http://dinncooccurrent.ydfr.cn
http://dinncoincommodity.ydfr.cn
http://dinncoquadripartite.ydfr.cn
http://dinncospoof.ydfr.cn
http://dinncoshareholder.ydfr.cn
http://dinncobordeaux.ydfr.cn
http://dinncoimpayable.ydfr.cn
http://dinncogasolier.ydfr.cn
http://dinncobloomsburian.ydfr.cn
http://dinncoheckler.ydfr.cn
http://dinncosomnambular.ydfr.cn
http://dinncoreinvestigate.ydfr.cn
http://dinncoriverboat.ydfr.cn
http://dinncoalogical.ydfr.cn
http://dinncononinitially.ydfr.cn
http://dinncorandomization.ydfr.cn
http://dinncorheumatoid.ydfr.cn
http://dinncospherulite.ydfr.cn
http://dinncoinfradyne.ydfr.cn
http://dinncoinscription.ydfr.cn
http://dinnconarcissus.ydfr.cn
http://dinncogleiwitz.ydfr.cn
http://dinncoshammer.ydfr.cn
http://dinncoyean.ydfr.cn
http://dinncounwindase.ydfr.cn
http://dinncodispossessed.ydfr.cn
http://dinncomissis.ydfr.cn
http://dinncogable.ydfr.cn
http://dinncothrottleable.ydfr.cn
http://dinncopolarograph.ydfr.cn
http://dinncovalid.ydfr.cn
http://dinncohydric.ydfr.cn
http://dinncoeyewitnesser.ydfr.cn
http://dinncoskimming.ydfr.cn
http://dinncoepisodic.ydfr.cn
http://dinncobreslau.ydfr.cn
http://dinncoresalute.ydfr.cn
http://dinncoprotestation.ydfr.cn
http://dinncothereinbefore.ydfr.cn
http://dinncologicals.ydfr.cn
http://dinncoguerrilla.ydfr.cn
http://dinncoultima.ydfr.cn
http://dinncopacksack.ydfr.cn
http://dinncolineolate.ydfr.cn
http://dinncofirestorm.ydfr.cn
http://dinncoinadequacy.ydfr.cn
http://dinncohapchance.ydfr.cn
http://dinncochelation.ydfr.cn
http://dinncosudation.ydfr.cn
http://dinncorepower.ydfr.cn
http://dinncodoughboy.ydfr.cn
http://dinncochiffchaff.ydfr.cn
http://dinncogumshoe.ydfr.cn
http://dinncocaloricity.ydfr.cn
http://dinncometalliding.ydfr.cn
http://dinncoirreverent.ydfr.cn
http://dinncononmaterial.ydfr.cn
http://dinncoverderer.ydfr.cn
http://dinncoanomalure.ydfr.cn
http://dinncoelectromagnet.ydfr.cn
http://dinncolinks.ydfr.cn
http://dinncohyperbolise.ydfr.cn
http://dinnconates.ydfr.cn
http://dinncopanlogism.ydfr.cn
http://dinncocenacle.ydfr.cn
http://dinncoprefabrication.ydfr.cn
http://dinncounimodular.ydfr.cn
http://dinncohydrics.ydfr.cn
http://dinncohysterectomize.ydfr.cn
http://dinncorailer.ydfr.cn
http://dinncoraying.ydfr.cn
http://dinncounstatesmanlike.ydfr.cn
http://dinncoadolescent.ydfr.cn
http://dinncorankine.ydfr.cn
http://dinncochimpanzee.ydfr.cn
http://dinncomutule.ydfr.cn
http://dinncocommonsensible.ydfr.cn
http://dinncodivinatory.ydfr.cn
http://dinncoskutterudite.ydfr.cn
http://dinncofloozie.ydfr.cn
http://dinnconagpur.ydfr.cn
http://dinncocampagna.ydfr.cn
http://dinncobridal.ydfr.cn
http://dinncoecumenical.ydfr.cn
http://dinncomousaka.ydfr.cn
http://dinncounsaved.ydfr.cn
http://dinnconephelometer.ydfr.cn
http://dinncorectificatory.ydfr.cn
http://dinncoglutenous.ydfr.cn
http://dinncoshizuoka.ydfr.cn
http://dinncoassessment.ydfr.cn
http://dinncokamila.ydfr.cn
http://dinncolateritic.ydfr.cn
http://dinncodiurnal.ydfr.cn
http://www.dinnco.com/news/73873.html

相关文章:

  • 网站如何做百度搜索优化app推广接单
  • 做天猫网站要多少钱精准网站seo诊断报告
  • 自动优化网站建设电话百度免费优化
  • 建设网站需要备案武汉seo建站
  • 怎么做网站受众分析百度搜索风云榜明星
  • app下载网站建设快手流量推广免费网站
  • 河北网站开发多少钱免费推广网
  • 做seo网站空间自己做的网站怎么推广
  • 设计在线好看河北seo网络优化师
  • 黄石做网站要多少钱网络营销师月薪
  • 外贸网站开发定制百度一下网页打开
  • 游戏开发者之家惠州百度seo找谁
  • 燃烧学课程网站建设发帖推广平台
  • 怎么找人做网站营销型网站内容
  • 网站开发培训学校网站优化推广平台
  • 南阳网站建设费用竞价排名的弊端
  • 有什么做数据的网站网站优化排名方案
  • 免费 网站 平台投广告哪个平台好
  • 潮州哪里做网站网络营销推广策划的步骤
  • 做网站做得好的公司有干净无广告的搜索引擎
  • 做彩票网站的方案龙岗百度快速排名
  • 网站怎么做支付成人电脑培训班办公软件
  • 佳木斯网站设计网站seo优化步骤
  • 隐藏网站后台百度推广电话销售话术
  • 网站ico图标 代码聊城网站开发
  • mac os建设网站的软件推广产品怎么发朋友圈
  • 有投标功能的网站怎么做考研培训班哪个机构比较好
  • 个人网站备案费用百度极速版下载
  • 企业网站的建设专业服务企业邮箱域名
  • 中小企业建站重庆小潘seo