UVa. 112, PKU 1145. Tree Summing. AC
#include int num,yes; char ch; int func(int sum) { int n,leaf=0; if(scanf(" %d",&n)) { sum+=n; scanf(" %c",&ch); leaf+=func(sum); scanf(" %c",&ch); leaf+=func(sum); if(leaf==2 && sum==num) { yes=1; } } else { if(scanf(" %c",&ch)) { if(ch==')') return 1; } } if(scanf(" %c",&ch)) { if(ch==')') return 0; } } main() { while (scanf("%d", &num) != EOF) { scanf(" %c",&ch); func(0); if(yes==1) puts("yes..
더보기