栈的应用:括号匹配检验
2018-03-26 21:17
253 查看
整点简单的哈哈哈#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int main()
{
stack<char> s;
char c;
int flag=0;
while((c=getchar())!='\n')
{
if(c=='{'||c=='['||c=='(')
{
s.push(c);
continue;
4000
}
if(c=='}')
{
if(!s.empty()&&s.top()=='{')
{
s.pop();
continue;
}
else
{
flag=1;
break;
}
}
if(c==']')
{
if(!s.empty()&&s.top()=='[')
{
s.pop();
continue;
}
else
{
flag=1;
break;
}
}
if(c==')')
{
if(!s.empty()&&s.top()=='(')
{
s.pop();
continue;
}
else
{
flag=1;
break;
}
}
}
if(s.empty()&&flag==0)
cout<<"yes!"<<endl;
else
cout<<"no!"<<endl;
}
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int main()
{
stack<char> s;
char c;
int flag=0;
while((c=getchar())!='\n')
{
if(c=='{'||c=='['||c=='(')
{
s.push(c);
continue;
4000
}
if(c=='}')
{
if(!s.empty()&&s.top()=='{')
{
s.pop();
continue;
}
else
{
flag=1;
break;
}
}
if(c==']')
{
if(!s.empty()&&s.top()=='[')
{
s.pop();
continue;
}
else
{
flag=1;
break;
}
}
if(c==')')
{
if(!s.empty()&&s.top()=='(')
{
s.pop();
continue;
}
else
{
flag=1;
break;
}
}
}
if(s.empty()&&flag==0)
cout<<"yes!"<<endl;
else
cout<<"no!"<<endl;
}
相关文章推荐
- 数据结构应用-----------括号匹配的检验
- 数据结构(8)--栈的应用之行编辑程序、括号匹配检验、数制转换、hanio塔问题
- 栈的应用之括号匹配的检验
- 栈应用--括号匹配的检验
- 栈的两个应用:括号匹配的检验和表达式求值
- 8、数据结构笔记之八栈的应用之括号匹配检验实现
- 栈的应用——括号匹配的检验(C语言)
- 栈的应用实践——括号匹配的检验
- 008.栈应用括号匹配的检验C实例
- 栈的应用--括号匹配的检验(C++)
- 数据结构题典021:栈的应用——括号匹配的检验(C++)
- 栈的应用之二----------括号匹配的检验
- 栈的应用之括号匹配检验
- 栈的应用--括号匹配的检验
- 数据结构 P49 栈的应用举例-括号匹配的检验
- 栈的应用1:数制转换、括号匹配检验和行编辑程序
- 栈的简单应用(数制转换、括号匹配检验、行编辑、迷宫求解)
- 递归应用之括号匹配检验
- 栈的应用之括号匹配的检验
- 栈的应用举例——括号匹配的检验