0
已解决
刘乐宸
新手天翼
新手天翼
#include <iostream>
#include <stack>
using namespace std;
char c;
stack<char> s;
int main() {
while(true) {
cin >> c;
if(c=='@') break;
if(c=='(') {
s.push(c);
}
else if(c==')'){
if(s.empty()) {
cout << "Wrong";
return 0;
}
else
s.pop();
}
if(c=='[') {
s.push(c);
}
else if(c==']'){
if(s.empty()) {
cout << "Wrong";
return 0;
}
else
s.pop();
}
}
if(s.empty()) cout << "OK";
else cout << "Wrong";
return 0;
}
50
刘乐宸在2020-07-21 11:36:40追加了内容
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include <stack>
using namespace std;
stack<char> s;
string a;
int main(){
// freopen("AC.in","r",stdin);
// freopen("AC.out","w",stdout);
cin>>a;
int k=a.size();
for(int i=0;i<k;i++){
if(a[i]=='('){
s.push(a[i]);
}
else if(a[i]==')'){
if(s.empty()){
cout<<"Wrong";
return 0;
}
else s.pop();
}
else if(a[i]=='['){
s.push(a[i]);
}
else if(a[i]==']'){
if(s.empty()){
cout<<"Wrong";
return 0;
}
else s.pop();
}
}
if(!s.empty()) cout<<"Wrong";
else cout<<"OK";
// fclose(stdin);
// fclose(stdout);
return 0;
}
//106.14.0.88:8100/ppt/s/?s=0f79d65c680d35f23bce1876c76101e72e174b1c7663eb2b6b8b01bf61e2849e
e,87分