SGU 461 Wiki Lists dfs
2015-07-30 19:20
344 查看
不难的题,不过蛮有意思的dfs
#include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <cstring> #include <map> #include <stack> #include <set> #define LL long long #define eps 1e-8 #define INF 0x3f3f3f3f //#define OPEN_FILE using namespace std; const char step[3][2][6] = { "<ul>", "</ul>", "<ol>", "</ol>", "<li>", "</li>" }; char s[1005][1005]; int m; void display(char ch, int f, int pos){ if (pos != 0 && !f){ printf("%s\n", step[2][0]); } if (ch == '*'){ if (f){ printf("%s\n", step[0][1]); } else{ printf("%s\n", step[0][0]); } } else{ if (f){ printf("%s\n", step[1][1]); } else{ printf("%s\n", step[1][0]); } } if (pos != 0 && f){ printf("%s\n", step[2][1]); } } void dfs(int p, int q, int pos){ while (p <= q){ if (s[p][pos] != '#' && s[p][pos] != '*'){ if (pos == 0){ printf("%s\n", s[p]); } else{ printf("%s\n%s\n%s\n", step[2][0], s[p] + pos, step[2][1]); } p++; continue; } int i; bool flag = false; for (i = p + 1; i <= q; i++){ if (s[i][pos] == s[p][pos]){ flag = true; } else{ break; } } i--; if (flag == true){ display(s[p][pos], 0, pos); dfs(p, i, pos + 1); display(s[p][pos], 1, pos); p = i + 1; } else{ if (pos == 0){ printf("%s\n", s[p]); } else{ printf("%s\n%s\n%s\n", step[2][0], s[p] + pos, step[2][1]); } p++; } } } int main() { #ifdef OPEN_FILE freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); #endif // OPEN_FILE m = 1; while (~scanf("%s", s[m])){ m++; } m--; dfs(1, m, 0); //printf("%d\n", m); }
相关文章推荐
- 每天一个小知识点18(Angularjs总结六)
- HDOJ 5336 XYZ and Drops 模拟
- 利用nodejs+phantomjs+casperjs采集淘宝商品的价格
- 杭电 2141 Can you find it?二分法+暴力查找
- leetcode之路017 Letter Combinations of a Phone Number
- C语言中的内存模型
- build path--use as source folder 应用
- iOS与服务器的对接
- android省市区三级联动案例:(三)主要功能实现
- java中添加日志
- 总线接口与计算机通信(五)CAN总线
- springMVC
- 键盘处理
- 行为金融学理论与股市关系,以及被恶意做空的私募圈
- poj1064 Cable master(hdoj1551)
- HDU5335.Walk Out
- hdu 4280 Island Transport(最大流)
- JSTL中<fmt:bundle >找不到properties文件的原因
- 暴力求解——UVA 572(简单的dfs)
- hdu5336 十滴水游戏的模拟