大佬们,蒟蒻求助

P1241 括号序列

@[EarthGiao](/space/show?uid=186489) 题目对不上
by dead_gun @ 2019-03-21 15:29:05


哦哦哦,大佬们我找到错误的地方了我忘了吧flag再变回初始值1了,QWQ.
by EarthGiao @ 2019-03-21 15:30:19


如果是codeVS上的话 正确代码: ```c #include<iostream> #include<stack> #include<cstring> #include<cstdio> using namespace std; char a[2000001]; int main() { int n; stack<int>s; int flag=1,i,j; cin>>n; for(i=1;i<=n;++i) { flag=1; scanf("%s",a); int l=strlen(a); for(j=0;j<l;++j) { if(a[j]=='('||a[j]=='{'||a[j]=='['||a[j]=='<') { s.push(a[j]); } else if(a[j]==')'&&!s.empty()&&s.top()=='(') { s.pop(); } else if(a[j]=='>'&&!s.empty()&&s.top()=='<') { s.pop(); } else if(a[j]=='}'&&!s.empty()&&s.top()=='{') { s.pop(); } else if(a[j]==']'&&!s.empty()&&s.top()=='[') { s.pop(); } else { flag=0; break; } } if(flag==1&&s.empty()) cout<<"TRUE"<<endl; else { cout<<"FALSE"<<endl; if(!s.empty()) { while(!s.empty()) { s.pop(); } } } memset(a,0,sizeof(a)); } return 0; } ``` 太阳留 @[EarthGiao](/space/show?uid=186489)
by dead_gun @ 2019-03-21 15:30:41


@[dead_gun](/space/show?uid=118869) 大佬是codves上的,嗯嗯嗯
by EarthGiao @ 2019-03-21 15:31:59


# @[dead_gun](/space/show?uid=118869) 发现野生太阳
by yu__xuan @ 2019-03-21 16:18:40


考古
by 拈花卜笑 @ 2019-07-28 09:53:23


|