dalao帮忙看看问题orz
查看原帖
dalao帮忙看看问题orz
466451
LYY_yyyy楼主2022/3/31 08:52

错误原因: terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc

This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. 代码:

#include<bits/stdc++.h>
using namespace std;
int T,n,m;
deque<char> s;
deque<char> r;
deque<char> t;
deque<char> a;
char xx,yy;
long long ans=0;
bool pd(deque<char> f)
{
    if(f.size()!=t.size()) return false;
    cout<<f.front();
    while(f.front()==t.front())
    {
        f.pop_front();t.pop_front();
    }
    if(!f.empty()) return false;
    return true;
}
void move(deque<char> f,deque<char> x)
{
    //cout<<f.front()<<' '<<x.front()<<endl;
    if(f.front()=='-')
    {   
        char l=x.front();
        f.pop_front();x.pop_front();
        move(f,x);x.push_front(l);x.pop_back();
        move(f,x);
    } 
    else
    {
        x.push_back(f.front());f.pop_front();
        move(f,x);
    }
    if(f.empty())
    {
        if(pd(x)) 
        {
            ans++;
            if(ans==1000000007) ans=0;
        }
        else return;
        return;
    }
}
int main()
{
    //freopen("string.in","r",stdin);
    //freopen("string.out","w",stdout);
    cin>>T;

    for(int i=1;i<=T;i++)
    {
        cin>>n>>m;
        for(int j=1;j<=n;j++)
        {
            cin>>xx;s.push_back(xx);
        }
        for(int j=1;j<=m;j++)
        {
            cin>>yy;t.push_back(yy);
        }
        r.push_back(s.front());s.pop_front();
        move(s,r);cout<<ans<<endl;
        ans=0;
        while(!s.empty()) s.pop_front();
        while(!t.empty()) t.pop_front();
        while(!r.empty()) r.pop_front();
    }
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}
2022/3/31 08:52
加载中...