第五周项目3-括号的匹配
来源:互联网 发布:如何介绍数据分析报告 编辑:程序博客网 时间:2024/06/07 09:46
解法1:
#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;}
解法2:
#include <stdio.h>#include "sqstack.h"bool isMatch(char *st){ int d=1, i; char c; SqStack *s; InitStack(s); 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) return true; else return false;}int main(){ char st[50]; printf("请输入表达式:"); scanf("%s", st); if(isMatch(st)) printf("配对正确!!\n"); else printf("配对错误!!\n"); return 0;}
阅读全文
0 0
- 第五周项目3--括号的匹配
- 第五周 项目3-括号的匹配
- 第五周项目3 -括号的匹配
- 第五周 项目3 - 括号的匹配
- 第五周项目3-括号的匹配
- 第五周项目3-括号的匹配
- 第五周项目3-括号的匹配
- 第五周 项目3-括号的匹配
- 第五周项目3-括号的匹配
- 第五周--项目3-括号的匹配
- 第五周 项目3 --括号的匹配
- 第五周项目3-括号的匹配
- 第五周项目3-括号的匹配
- 【第五周项目3-括号的匹配】
- 第五周项目3--括号的匹配
- 第五周项目3-括号的匹配
- 第五周项目3-括号的匹配
- 第五周--项目3括号的匹配 .
- sketch常用快捷键键盘对应
- 面试问答
- 第三周 顺序表的基本运算
- 字节流转换为字符流
- 最大/小子数组
- 第五周项目3-括号的匹配
- 发送JSON数据到服务器
- 调度
- lecture6,Training Neural Networks, Part I
- 剑指offer 33 把数组排成最小的数
- 17 全表扫描成本计算--优化主题系列
- python socket 实现的简单http服务器
- mysql查询数据库所有表和字段及其注释
- 微信手机支付