POj 1145
伤不起呀
#include <stdio.h> int n; int flag; char inputFilter() { char c; while(scanf("%c",&c)&&c==' '||c=='\n'||c==9||c==10); return c; } int dfs(int sum,int height) { char c; int sign=1; int count=0; c=inputFilter();//个人认为此处是本题的关键点1 if(c==')') return height; if(c=='-') { sign=-1; c=inputFilter(); } while(c>='0'&&c<='9') { count=count*10+sign*(c-'0'); scanf("%c",&c); } if(c=='\n'||c==' ') c=inputFilter(); int k1=dfs(sum+count,height+1); c=inputFilter(); int k2=dfs(sum+count,height+1); c=inputFilter(); if(k1==height+1&&k2==height+1)//关键点2,判断终结点 { if(sum+count==n) flag=1; } return 0; } int main() { while(scanf("%d",&n)!=EOF) { flag=0; inputFilter();//使dfs第4 行的C读的是(后面的字符 dfs(0,0); if(flag==1) printf("yes\n"); else printf("no\n"); } return 0; }