蒟蒻求助
查看原帖
蒟蒻求助
244059
king_xbz楼主2020/9/27 12:27

同样的代码把字符变量ch设为全局变量就WA了,设为局部变量就AC了。本来我以为是初始值的问题,但是事实上在函数内为ch赋初值并不能使这个程序AC。

这是30PTS的代码

char ch;
inline int dfs(int x)
{
	ch=' ';
	while(cin>>ch)
	{
		if(ch=='a')
		x++;
		if(ch=='(')
		x+=dfs(0);
		if(ch==')')
		return x;
		if(ch=='|')
		return x=max(x,dfs(0));
	}
	return x;
}

这是满分AC的代码:

inline int dfs(int x)
{
	char ch;ch=' ';
	while(cin>>ch)
	{
		if(ch=='a')
		x++;
		if(ch=='(')
		x+=dfs(0);
		if(ch==')')
		return x;
		if(ch=='|')
		return x=max(x,dfs(0));
	}
	return x;
}

所以小蒟蒻就疑惑辽!大佬们快来帮帮我这只菜菜⑧!

2020/9/27 12:27
加载中...