求助dalao
  • 板块灌水区
  • 楼主so_yaya
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/8/21 20:05
  • 上次更新2023/11/3 02:09:22
查看原帖
求助dalao
920133
so_yaya楼主2023/8/21 20:05

样例过了 wa40分 逻辑表达式

#include<bits/stdc++.h>
using namespace std;
string s;
bool pd;
int ans1,ans2,off;
int main()
{
	ios::sync_with_stdio(false);
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(off)
		{
			if(s[i]=='(')
			{
				int x=1;
				while(x)
				{
					i++;
					if(s[i]=='(') x++;
					if(s[i]==')') x--;
				}
			}
			else if(off==1&&s[i]=='|')
			{
			 off=0;
			}
			else if(s[i]=')')
			{
				off=0;
			}
			else if(off==1&&s[i]=='&')
			{
				ans1++;
			}
			else if(off==2&&s[i]=='|')
			{
				ans2++;
			}
		}
		else
		{
			if(s[i]=='1') pd=1;
			if(s[i]=='0') pd=0;
			if(s[i]=='&'&&pd==0)
			{
				off=1;
				ans1++;
			}
			if(s[i]=='|'&&pd==1)
			{
				off=2;
				ans2++;
			}
		}
	}
	cout<<pd<<endl<<ans1<<" "<<ans2<<endl;
	return 0;
}
2023/8/21 20:05
加载中...