poj1145 括号间的读取与匹配
来源:互联网 发布:java获取浏览器地址 编辑:程序博客网 时间:2024/06/06 16:42
#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>using namespace std;char ans[110];int flag;int x;void sovle(int s, int e, int res, int x) { if(e -1 == s) return; char str[30]; int k = 0, i,j; int n = 0; for(i = s+1; ; i++){ if(ans[i] == '(') break; str[k++] = ans[i]; } str[k] = '\0'; int tem = atoi(str); // printf("\ntem = %d\n", tem); res += tem; // printf("tem = %d res = %d \n",tem, res); if(i + 4 == e && res == x){ flag = 1; } for(j = i; ; j++){ if(ans[j] == '(') n++; if(ans[j] == ')') n--; if(n == 0) break; } sovle(i, j, res, x); sovle(j + 1, e -1, res, x);}int main(){ char ch; int n = 0; int k = 0; while(cin>>x) { k = 0; n = 0; flag = 0; while(cin>>ch) { if(ch == ' ') continue; ans[k++] = ch; if(ch == '(') n++; if(ch == ')') n--; if(n == 0) break; } sovle(0, k -1, 0, x); if(flag) printf("yes\n"); else printf("no\n"); } return 0;}
0 0
- poj1145 括号间的读取与匹配
- poj1145
- poj1145
- 括号匹配的检验
- 括号的匹配方法
- 括号的匹配检验
- 括号匹配的检验
- 括号匹配的方法
- 括号的匹配问题
- 括号匹配的检验
- 简单的括号匹配
- 括号匹配的检验
- 括号的匹配
- 简单的括号匹配
- 匹配括号的算法
- 括号的匹配
- 括号的匹配
- 括号匹配的检验
- 平凡与非凡的差异仅在于那一点点额外的努力
- work_weipa_打字时界面上移问题
- linux进程优先级设置
- 服务器操作系统应该选择 Debian/Ubuntu 还是 CentOS?
- IOS 基础知识 Foundation-NSString和NSMutableString的使用
- poj1145 括号间的读取与匹配
- 视图的使用
- 网络协议分析--Ethereal网络协议分析及介绍
- STL vector中的end方法(8)
- block 和 全局变量
- 索引-数学
- NSString
- linux中 you have newmail in /var/spool/mail/root是什么意思
- UVA - 10916 Factstone Benchmark