题意不难理解,水题,不必建树,可以直接字符操作。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctype.h>
int n;
int sum[105];
char str;
int main()
{
// freopen("D:\\1.txt","r",stdin);
while(scanf("%d",&n) != EOF)
{
bool flag = false, lead = false;
int x = -1;
int count = 0, m = 0;
char ch = '#';
memset(sum,0,sizeof(sum));
for(;count || ch == '#';)
{
str = getchar();
if(str == ' ' || str == '\n')
continue;
if(str == '-')
{
lead = true;
}
if(isdigit(str))
{
if(x < 0)
x = 0;
x = x * 10 + str - '0';
m = 0;
}
if(x > -1 && !isdigit(str))
{
sum[count] = sum[count-1] + (lead ? -1*x : x);
x = -1;
lead = false;
}
if(str == ')')
{
if(ch == '(')
{
count--;
m++;
}
if(sum[count] == n && !flag && m >= 2)
{
flag = true;
// break;
}
if(ch != '(')
{
m = 0;
count--;
}
}
if(str == '(')
count++;
ch = str;
}
if(flag) printf("yes\n");
else printf("no\n");
}
return 0;
}