uva 112 - Tree Summing
来源:互联网 发布:公主坟软件培训 编辑:程序博客网 时间:2024/05/22 15:07
wa了两次,就是少了负数和0()的情况。。。。
#include <iostream>#include <cstdio>#include <cstring>#include <iterator>#include <cmath>#include <algorithm>#include <stack>using namespace std;stack<char> s;stack<int> num;int n, flag, ok;char ch;void dfs(int sum){ if(ch == '(') { flag++; s.push(ch); int a = 0; int fushu = 0; while(cin >> ch) { if(ch == '-') { fushu = 1; continue; } if(isdigit(ch)) a = a*10 + ch-'0'; else break; } if(fushu) a = -a; if(ch == ')') { flag++; s.pop(); if(flag == 4) if(sum == n) ok++; if(s.empty()) return; cin >> ch; dfs(sum); } else { flag = 0; sum+=a; num.push(a); dfs(sum); } } else if(ch == ')') { flag = 0; s.pop(); if(s.empty()) return; else { cin >> ch; int mark = num.top(); num.pop(); dfs(sum-mark); } }}int main(){ while(cin >> n) { ok = 0; flag = 0; cin >> ch; dfs(0); if(ok) cout << "yes" << endl; else cout << "no" << endl; } return 0;}
- uva 112 Tree Summing
- uva 112 - Tree Summing
- uva 112 - Tree Summing
- UVa 112 - Tree Summing
- uva 112 - Tree Summing
- uva 112 Tree Summing
- UVA 112 Tree Summing
- UVa 112 - Tree Summing
- UVa 112 - Tree Summing
- UVa 112 - Tree Summing
- uva 112 - Tree Summing
- uva-112 Tree Summing
- UVA 112 Tree Summing
- UVA 112 Tree Summing
- UVa 112 Tree Summing
- UVa 112 Tree Summing
- UVA 112 Tree Summing
- uva 112 Tree Summing
- 备胎——拿得起要放得下
- 马尔科夫状态转移矩阵的一个性质,以及一个直观的图形证明
- State 模式
- 遇到的一些 问题记录
- HTML中单位em和px
- uva 112 - Tree Summing
- multimap::insert (STL/CLR)--VS2010
- ETL系列专题2——ETL中的数据结构
- struts2技术内幕笔记2(struts2概览与设计模式)
- 普京的讲话为何震撼中国人?
- 未能从程序集“System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”中加载
- In Life It's Not Where You Go-It's Who You Travel With.
- could not create /tmp
- 难以翻译的单词