E只能过50%,求大神看看哪个地方有问题

#include <bits/stdc++.h>

using namespace std;

#define int long long

signed main() {

stack<char> p;

vector<int> q;

int t;

cin>>t;

int l=0;

for(int i=0;i<2*t;i++)

{

char r;

cin>>r;

if(r=='(')

p.push(r);

if(!p.empty())

if(p.top()=='('&&r==')')

{

p.pop();

l++;

}

if(p.empty())

{

q.push_back(l);

l=0;

}

}

if(!p.empty())

cout<<-1;

else

{

int ans=0;

for(int i=0;i<q.size();i++)

ans+=q[i];

for(int i=0;i<q.size();i++)

{

for(int j=1;j<=q[i];j++)

{

cout<<ans-j<<" ";

}

}

}

}

全部评论
3221
1 回复 分享
发布于 02-16 21:47 安徽
(()(()))
1 回复 分享
发布于 02-16 21:39 安徽

相关推荐

07-01 13:37
门头沟学院 Java
steelhead:不是你的问题,这是社会的问题。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务