[HDOJ1274]展开字符串
2015-09-04 02:54
399 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1274
递归题。
递归题。
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <iostream> #include <cmath> #include <cctype> #include <queue> #include <map> #include <set> #include <stack> #include <list> #include <vector> using namespace std; char str[66666]; int len; int solve(int pos) { while(str[pos] != ')' && pos < len) { int t = 0; while(isdigit(str[pos])) { t = t * 10 + str[pos++] - '0'; } if(t == 0) { t++; } int now = -1; while(t--) { if(str[pos] == '(') { now = solve(pos+1); } else { printf("%c", str[pos]); } } if(now != -1) { pos = now; } pos++; } return pos; } int main() { // freopen("in", "r", stdin); int T; scanf("%d", &T); getchar(); while(T--) { memset(str, 0, sizeof(str)); gets(str); len = strlen(str); solve(0); printf("\n"); } return 0; }
相关文章推荐
- 【Python基础】模块
- 开源分享 一(StickerCamera + 仿微信多图选择)
- 几部科幻小说的评价和感想
- C++重载逗号,括号,类型转换,实现以奇怪的方式给变量赋值
- linux之权限管理
- 考虑
- [Flux] 1. Development Environment Setup
- Leetcode Unique Binary Search Trees II
- C# 比较目录
- c语言指针基本使用
- spark源码剖析之----Shuffle
- ubuntu 64位下安装 texlive2015 并设置 ctex 中文套装
- 云主机环境搭建教程之搭建全能主机
- 线程网格(grid)
- [HDOJ1087]Super Jumping! Jumping! Jumping!
- POJ1066Treasure Hunt【判断直线相交】
- POJ 1056 解题报告
- clearcase 中一些概念和操作
- clearcase 中一些概念和操作
- C/C++ Resources