跳到正文

题解

题解:AT_xmascon24_b BNF Backup

jnsk约 4 分钟
原文
文章信息与版本

文章信息

发布
2026年10月3日
收录
2026年10月4日
更新
2026年10月4日
篇幅
约 4 分钟
获赞
1

版本

  1. v1当前

人类智慧题。

思路

通过手玩样例可以发现,每个 _ 上填的东西只与它前后一个数有关。

我们发现这个字符串只由 + 、0 、( 、) 组成。

于是我们可以对每个 _ 前后的字符进行判断,共计 4×44\times4 种组合。

在头和尾 _ 需要特判,长度为 11 也要特判。

具体看代码吧。

code

C++
#include<bits/stdc++.h>
using namespace std;
string t;
int len;
int main(){

	cin>>t;
	len=t.size();
	if(len==1)
	{
		cout<<0;
		return 0;
	}
	t='#'+t;
	for(int i=1;i<=len;i++)
	{
		if(t[i]=='_')
		{
			if(i==1&&t[i+1]=='0')
			{
				t[i]='(';
			}
			else if(i==1&&t[i+1]=='(')
			{
				t[i]='(';
			}
			else  if(i==1&&t[i+1]=='+')
			{
				t[i]='0';
			}
			// ) 和 “ ” 不可能 
			
			else  if(i==len&&t[i-1]==')')
			{
				t[i]=')';
			}
			else if(i==len&&t[i-1]=='0')
			{
				t[i]=')';
			}
			else if(i==len&&t[i-1]=='+')
			{
				t[i]='0';
			}
			// ( 和 “ ” 不可能
			else if(t[i-1]=='('&&t[i+1]==')')
			{
				t[i]='0';
			}
			else if(t[i-1]=='('&&t[i+1]=='(')
			{
				t[i]='(';
			}
			else if(t[i-1]=='('&&t[i+1]=='0')
			{
				t[i]='(';
			}
			else if(t[i-1]=='('&&t[i+1]=='+')
			{
				t[i]='0';
			}
			//________
			else if(t[i-1]==')'&&t[i+1]==')')
			{
				t[i]=')';
			}
			else if(t[i-1]==')'&&t[i+1]=='(')
			{
				t[i]='+';
			}
			else if(t[i-1]==')'&&t[i+1]=='0')
			{
				t[i]='+';
			}
			else if(t[i-1]==')'&&t[i+1]=='+')
			{
				t[i]=')';
			}
			//________
			else if(t[i-1]=='0'&&t[i+1]==')')
			{
				t[i]=')';
			}
			else if(t[i-1]=='0'&&t[i+1]=='(')
			{
				t[i]='+';
			}
			else if(t[i-1]=='0'&&t[i+1]=='0')
			{
				t[i]='+';
			}
			else if(t[i-1]=='0'&&t[i+1]=='+')
			{
				t[i]=')';
			}
			//________
			else if(t[i-1]=='+'&&t[i+1]==')')
			{
				t[i]='0';
			}
			else if(t[i-1]=='+'&&t[i+1]=='(')
			{
				t[i]='(';
			}
			else if(t[i-1]=='+'&&t[i+1]=='0')
			{
				t[i]='(';
			}
			else if(t[i-1]=='+'&&t[i+1]=='+')
			{
				t[i]='0';
			}
		 } 
	} 
	for(int i=1;i<=len;i++)
	{
		cout<<t[i];
	}
	return 0;
} 
原文