同样的代码把字符变量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;
}
所以小蒟蒻就疑惑辽!大佬们快来帮帮我这只菜菜⑧!