玄关求调
查看原帖
玄关求调
1399690
Enteral楼主2024/10/18 12:51

奇怪的做法……80pts玄关求调

#include<bits/stdc++.h>
using namespace std;
char s[1000010]; 
int main()
{
	cin>>s;
	long long len=strlen(s),f=1,ans=0,shortcut1=0,shortcut2=0;
	for(int i=0;i<len;i++)
	{
		if(f==1)
		{
			if(ans==0&&s[i]=='&')//find shortcut
			{
				f=0;
				ans=0;
				shortcut1++;
				goto nxt;
			}
			if(ans==1&&s[i]=='|')
			{
				f=0;
				ans=1;
				shortcut2++;
				goto nxt;
			}
			if(s[i]=='0'||s[i]=='1')
			{
				ans=s[i]-'0';
			}
			if(s[i]=='('||s[i]==')'||s[i]=='|'||s[i]=='&')continue;
		}
		nxt:;
		if(f==0)
		{
			if(s[i]=='&')
			{
				int l=0;
				i++;
				if(s[i]=='('){
				l++;	
				}
				//i++;
				while(l>0)
				{
					if(i==len-1){
						i--;break;
					}
					i++;
					if(s[i]=='(')l++;
					if(s[i]==')')l--;
				}
			}
			else if(s[i]=='|')
			{
				int l=0;
				i++;
				if(s[i]=='('){
				l++;	
				}
				while(l>=0)
				{
					if((s[i]=='|'&&l==0)||i==len-1){
						i--;break;
					}
					i++;
					if(s[i]=='(')l++;
					if(s[i]==')')l--;
				}
			}
			f=1;
		}
	}
	cout<<ans<<endl<<shortcut1<<" "<<shortcut2;
	return 0;
}
2024/10/18 12:51
加载中...