玄学问题求助
查看原帖
玄学问题求助
1176033
vinegarchen楼主2024/10/1 11:20

45分代码如下:

#include<bits/stdc++.h>
#define int long long
using namespace std;
int c1,c2,len;
char str[1000005];
int run(int st)
{
	int z=1;
	while(z>0)
	{
		st++;
		if(str[st]=='(') z++;
		if(str[st]==')') z--;
	}
	return st;
}
signed main()
{
	scanf("%s",&str);
	len=strlen(str);
	int i=0,z=0;
	while(i<len-1)
	{
		if(str[i]=='0'&&str[i+1]=='&')
		{
			if(str[i+2]=='(') i=run(i+2);
			else i+=2;
			str[i]='0',c1++; 
		}
		if(str[i]=='1'&&str[i+1]=='|')
		{
			if(str[i+2]=='(') i=run(i+2);
			else
			{
				i+=2,z=0;
				while(str[i]!='|')
				{
					if(str[i]=='(') i=run(i),z++;
					if(str[i]==')')
					{
						z--;
						if(z<0)
						{
							i++;
							break;
						}
					}
					i++; 
				}
				i--; 
			}
			str[i]='1',c2++;
		}
		if((str[i]=='0'&&str[i+1]=='|')||(str[i]=='1'&&str[i+1]=='&')) i+=2;
		if(str[i]=='(') i++;
		if(str[i+1]==')')
		{
			str[i+1]=str[i];
			i++;
		}
	}
	printf("%c\n%d %d",str[len-1],c1,c2);
	return 0;
}

奇怪的是RE了一些点,下载下来一看:

输入:1|1
输出:1
     0 1

但在本地测后,发现并没有RE,而且输出完全正确。

2024/10/1 11:20
加载中...