![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a7508d1faa2a502ec1377292683c050e.png)
OJ新平台提交的第一题
1,getling(cin,s);
gets(s)
2,栈的操作
int a = s.top();
s.pop();
s.push();
s.size();
栈只能队栈顶元素操作,不能操作其他位置。
#include <iostream>
#include <bits/stdc++.h>
#include <stack>
using namespace std;
int w,f;
int main(){
string ss;
char sss[105];
while(getline(cin ,ss)){
w = 0;
f = 1;
for(int i = 0;i < ss.size(); i++){
if(ss[i] == '(' || ss[i] == ')' || ss[i] == '[' || ss[i] == ']' || ss[i] == '{' || ss[i] == '}'){
sss[w++] = ss[i];
}
}
stack<char>s;
for(int i = 0; i < w; i++){
if(sss[i] == '(' || sss[i] == '[' || sss[i] == '{'){
s.push(sss[i]);
}else if(s.size() == 0){
f = 0;
break;
}else{
while(s.size() > 0){
if(s.top() == sss[i] - 1 || s.top() == sss[i] - 2){
s.pop();
break;
}else {
break;
}
}
}
}
if(f == 0){
cout << "no" << endl;
}else{
if(s.size() != 0){
cout << "no" << endl;
}else{
cout << "yes" <<endl;
}
}
while(!s.empty()){
s.pop();
}
}
return 0;
}