第五周-项目二-括号的匹配(栈)
来源:互联网 发布:json在qt中的使用 编辑:程序博客网 时间:2024/06/07 02:26
/* * Copyright (c) 2017,烟台大学计算机学院 * All right reserved. * 文件名称:main.cpp * 作者:马明祥 * 完成日期:2017年12月07日 * 版本号:v1.0 * * 问题描述:括号的匹配(栈) * 输入描述:标准函数输入 * 程序输出:标准函数输出 /*假设表达式中允许三种括号:圆括号、方括号和大括号。编写一个算法,判断表达式中的各种左括号是否与右括号匹配。
例如,输入2+(3+4)*2+{[3]}-8,输出匹配正确;输入2+(3+4*[2)+{[3]}-8,输出匹配错误。
#include <stdio.h>#include "sqstack.h"int main(){ char c; char st[50]; int d=1, i; SqStack *s; InitStack(s); printf("请输入表达式:"); scanf("%s", st); for(i=0; st[i]!='\0'&&d; i++) { switch(st[i]) { case'(': case'[': case'{': Push(s, st[i]); break; case')': Pop(s, c); if(c!='(') d=0; break; case']': Pop(s, c); if(c!='[') d=0; break; case'}': Pop(s,c); if(c!='{') d=0; break; } } if(StackEmpty(s)&&d==1) printf("配对正确!!\n"); else printf("配对错误!!\n"); return 0;}运行结果:
阅读全文
0 0
- 第五周-项目二-括号的匹配(栈)
- 第五周-项目二-2-括号的匹配(栈)
- 第五周项目3--括号的匹配
- 第五周 项目3-括号的匹配
- 第五周项目3 -括号的匹配
- 第五周 项目3 - 括号的匹配
- 第五周项目3-括号的匹配
- 第五周项目3-括号的匹配
- 第五周项目3-括号的匹配
- 第五周项目三 括号的匹配
- 第五周【项目三-括号的匹配】
- 第五周 项目3-括号的匹配
- 第五周项目3-括号的匹配
- 第五周--项目3-括号的匹配
- 第五周- 项目三 括号的匹配
- 第五周--项目三--括号的匹配
- 第五周项目三-括号的匹配
- 第五周 项目3 --括号的匹配
- Eclipse+Maven(webapp)+Jetty+JReBel的配置方法
- error while loading shared libraries: ***.so: cannot open shared object file: No such file or direct
- 第十三周项目四
- url参数中有+、空格、=、%、&、#等特殊符号的问题解决
- 第十五周内部排序(2)项目1---(2)希尔排序
- 第五周-项目二-括号的匹配(栈)
- 数据库中间件cobar调研笔记
- 注解@Autowired和@Resource的区别
- 如何将已经建好的项目导入到Scala IDE forEclipse中
- TypeError:undefined is not a function
- R中利用apply、tapply、lapply、sapply、mapply、table等函数进行分组统计
- 漏测缺陷库
- 第五周 【项目1
- 我最常用的Intellij IDEA快捷键