ZOJ-2571 Big String Outspread 模拟
2013-04-15 23:24
295 查看
题意:给定一个字符串,按照要求输出来。
解法:每次进行一次首字母判定,然后根据不同的情况进行递归。
代码如下:
解法:每次进行一次首字母判定,然后根据不同的情况进行递归。
代码如下:
#include <cstdlib> #include <cstdio> #include <cstring> #include <string> #include <iostream> #include <algorithm> using namespace std; char str[300]; string display(int ti, int sta, int fuck) { string ret; if (sta > fuck) return ret; if (sta == fuck && !isalpha(str[sta])) return ret; string tmp; if (!isalpha(str[sta])) { // 如果不是以字符开始 if (isdigit(str[sta])) { int t = 0, i, j; for (i = sta; isdigit(str[i]); ++i) { // 如果是数字的话 t = t * 10 + (str[i] - '0'); // 得出循环的次数数字 } if (str[i] != '(') { // 如果后面不是括号,那么只有一位 tmp = display(t, i, i) + display(1, i+1, fuck); } else { int cnt = 0; for (j = sta; ; ++j) { // 找到括号在的位置 if (str[j] == ')') { --cnt; if (!cnt) break; } else if (str[j] == '(') ++cnt; } tmp = display(t, i+1, j-1) + display(1, j+1, fuck); } } else { // 如果是括号进入 int cnt = 0, j; for (j = sta; ; ++j) { if (str[j] == ')') { --cnt; if (!cnt) break; } else if (str[j] == '(') ++cnt; } tmp = display(1, sta, j-1) + display(1, j+1, fuck); } while (ti--) { ret += tmp; } } else { tmp = str[sta] + display(1, sta+1, fuck); while (ti--) ret += tmp; // 把后面的这一个字母进行重复 } return ret; } int main() { int T, len; scanf("%d", &T); while (T--) { scanf("%s", str); len = strlen(str); cout << display(1, 0, len-1) << endl; } return 0; }
相关文章推荐
- ZOJ 2571 Big String Outspread
- zoj 2571 Big String Outspread
- ZOJ 2571 Big String Outspread
- zoj1633 Big String dfs
- ZOJ 3985 String Of CCPC 字符串,模拟
- ZOJ&nbsp;1633&nbsp;big&nbsp;string
- ZOJ 3818 Pretty Poem (暴力模拟 string(substr))
- ZOJ 3333(L)模拟
- ZOJ 3603 Draw Something Cheat (模拟)
- zoj 3627#模拟#枚举
- ZOJ-1060-Sorting It All Out
- ZOJ 2971 模拟 (G)
- ZOJ 1354(枚举,模拟)
- ZOJ 3600 Taxi Fare【模拟】
- ZOJ 1610 Count the Colors(数组模拟)
- ZOJ-3715-Kindergarten Election(贪心 枚举 模拟)
- UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据
- ZOJ 2971 Give Me the Number(模拟)
- BigInteger应用于概率DP ZOJ 3380 WA TLE
- zoj 3878【打表模拟】