比赛 CSP2022普及组 评测结果 AAAAWWWWWWWWWWWWWWWW
题目名称 逻辑表达式 最终得分 20
用户昵称 liuyiche 运行时间 0.151 s
代码语言 C++ 内存使用 3.17 MiB
提交时间 2022-10-29 17:48:39
显示代码纯文本
#include <bits/stdc++.h> 
 
using namespace std;

int main()
{
	freopen("csp2022pj_expr.in","r",stdin);
	freopen("csp2022pj_expr.out","w",stdout);
 	
 	string s;
 	cin >> s;
 	
 	if(s.length() == 1)
    {
        cout << s[0] << endl << 0 << " " << 0;
        return 0;
    }
    if(s.length()==3)
    {
        if(s[1]=='&')
        {
            cout<< ((s[0]-'0')&(s[2]-'0')) << endl;
            if (s[0]=='0') 
				cout<<1;
            else 
				cout << 0;
            cout << " " << 0;
        }
        else 
        {
            cout<< ((s[0]-'0')|(s[2]-'0')) << endl;
            cout << 0 << " ";
            if(s[0]=='1') 
				cout << 1;
            else
				 cout << 0;
        }
        return 0;
    }
    if(s.length() == 5)
    {
        if(s[1]=='|'&&s[3]=='&') 
        {
            cout<< ((s[2]-'0')&(s[4]-'0')|(s[0]-'0')) << endl;
            if(s[0]=='1') 
				cout << 0 << " " << 1;
            else if(s[2]=='0') 
				cout << 1 << " " << 0;
            else 
				cout << 0<< " " << 0;
        }
        else if(s[1]=='|'&&s[3]=='|')
    	{
                 cout<<((s[0]-'0')|(s[2]-'0')|(s[4]-'0'))<<endl;
                 if(s[0]=='1') 
				 	cout<<0<<" "<<2;
                 else if(s[2]=='1') 
				 	cout<<0<<" "<<1;
                 else 
				 	cout<<0<<" "<<0;
        }
        else if(s[1]=='&'&&s[3]=='|')
        {
                cout<<((s[0]-'0')&(s[2]-'0')|(s[4]-'0'))<<endl;
                if(s[0]=='0') cout<<1<<" "<<0;
                else if(s[2]=='1') 
				 	cout<<0<<" "<<1;
                else 
					cout<<0<<" "<<0;
        }
                else
                {
                    cout<<((s[0]-'0')&(s[2]-'0')&(s[4]-'0'))<<endl;
                    if(s[0]=='0') 
						cout<<2<<" "<<0;
                    else if(s[2]=='0') 
						cout<<1<<" "<<0;
                    else 
						cout<<0<<" "<<0;
                }
        return 0;
    }
 	
 	cout << 0 << endl << 0 << " " << 0;
	
	return 0;
}