囧,改后更错了
查看原帖
囧,改后更错了
602932
NumberTrart楼主2023/5/17 20:38

改前30

#include<iostream>
#include<sstream>
#include<stack>
#define test 0
using namespace std;
string s,ss,tmps;
int n,q,tmp,temp,ttmp;
bool x[100005],btmp,btemp;
stack<bool> st;
int s2i(string s)
{
	int ret=0;
	for(int i=0;i<s.size();i++)
		ret=ret*10+s[i]-'0';
	return ret;
}
string _s[500005];
int main()
{
    getline(cin,s);
    cin>>n;
    s=s+" _";
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&tmp);
        x[i]=tmp;
    }
    cin>>q;
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&tmp);
        x[tmp]=!x[tmp];
        ss=s;
        while(ss!="_")
        {
            temp=ss.find(' ');
            tmps=ss.substr(0,temp);
            ss=ss.substr(temp+1);
			#if test
			cout<<"temp:"<<temp<<" tmps:"<<tmps<<" count:"<<st.size()<<'\n';
			#endif
            if(tmps[0]=='x')
            {
                ttmp=s2i(tmps.substr(1));
				#if test
				cout<<"x["<<ttmp<<"]="<<x[ttmp]<<'\n';
				#endif
                st.push(x[ttmp]);
            }
            else if(tmps=="&")
            {
                btmp=st.top();
                st.pop();
                btemp=st.top();
                st.pop();
                #if test
				cout<<btemp<<'&'<<btmp<<'\n';
				#endif
                st.push(btmp&&btemp);
            }
            else if(tmps=="|")
            {
                btmp=st.top();
                st.pop();
                btemp=st.top();
                st.pop();
                #if test
				cout<<btemp<<'|'<<btmp<<'\n';
				#endif
                st.push(btmp||btemp);
            }
            else if(tmps=="!")
            {
                btmp=st.top();
                st.pop();
                #if test
				cout<<"!"<<btmp<<'\n';
				#endif
                st.push(!btmp);
            }
            else
            {
                cout<<tmps<<"What is that?";
                return 0;
            }
        }
        x[tmp]=!x[tmp];
        if(st.size()!=1)
        {
            cout<<"Wrong-code alarm"<<st.size();
            return 0;
        }
        cout<<int(st.top())<<'\n';
        st.pop();
    }
    return 0;
}

改后5分

#include<iostream>
#include<sstream>
#include<stack>
#define test 0
using namespace std;
string s,ss,tmps;
int n,q,tmp,temp,ttmp;
bool x[100005],btmp,btemp;
stack<bool> st;
int s2i(string s)
{
	int ret=0;
	for(int i=0;i<s.size();i++)
		ret=ret*10+s[i]-'0';
	return ret;
}
string _s[500005];
int _x[500005],cnt;
int main()
{
    getline(cin,ss);
    cin>>n;
    ss=ss+" _";
    while(ss!="_")
    {
        temp=ss.find(' ');
        tmps=ss.substr(0,temp);
        ss=ss.substr(temp+1);
		#if test
		cout<<"temp:"<<temp<<" tmps:"<<tmps<<" count:"<<st.size()<<'\n';
		#endif
        if(tmps[0]=='x')
        {
            ttmp=s2i(tmps.substr(1));
			#if test
			cout<<"x["<<ttmp<<"]"<<'\n';
			#endif
            _s[++cnt]="x";
            _x[cnt]=ttmp;
        }
        else if(tmps=="&")
        {
            #if test
			cout<<btemp<<'&'<<btmp<<'\n';
			#endif
            _s[++cnt]="&";
        }
        else if(tmps=="|")
        {
            #if test
			cout<<btemp<<'|'<<btmp<<'\n';
			#endif
            _s[++cnt]="|";
        }
        else if(tmps=="!")
        {
            #if test
			cout<<"!"<<btmp<<'\n';
			#endif
            _s[++cnt]='!';
        }
        else
        {
            cout<<tmps<<"What is that?";
            return 0;
        }
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&tmp);
        x[i]=tmp;
    }
    cin>>q;
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&tmp);
        x[tmp]=!x[tmp];
        for(int i=1;i<=cnt;i++)
        {
            if(_s[i]=="x")
            {
                st.push(_x[i]);
            }
            else if(_s[i]=="&")
            {
                btmp=st.top();
                st.pop();
                btemp=st.top();
                st.pop();
                #if test
				cout<<btemp<<'&'<<btmp<<'\n';
				#endif
                st.push(btmp&&btemp);
            }
            else if(_s[i]=="|")
            {
                btmp=st.top();
                st.pop();
                btemp=st.top();
                st.pop();
                #if test
				cout<<btemp<<'|'<<btmp<<'\n';
				#endif
                st.push(btmp||btemp);
            }
            else if(_s[i]=="!")
            {
                btmp=st.top();
                st.pop();
                #if test
				cout<<"!"<<btmp<<'\n';
				#endif
                st.push(!btmp);
            }
            else
            {
                cout<<_s[i]<<"What is that?";
                return 0;
            }
        }
        x[tmp]=!x[tmp];
        if(st.size()!=1)
        {
            cout<<"Wrong-code alarm"<<st.size();
            return 0;
        }
        cout<<int(st.top())<<'\n';
        st.pop();
    }
    return 0;
}

囧

2023/5/17 20:38
加载中...