SGU 461 Wiki Lists dfs
不难的题,不过蛮有意思的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[][][] = { "<ul>", "</ul>", "<ol>", "</ol>", "<li>", "</li>" };
char s[][];
int m; void display(char ch, int f, int pos){
if (pos != && !f){
printf("%s\n", step[][]);
}
if (ch == '*'){
if (f){
printf("%s\n", step[][]);
}
else{
printf("%s\n", step[][]);
}
}
else{
if (f){
printf("%s\n", step[][]);
}
else{
printf("%s\n", step[][]);
}
}
if (pos != && f){
printf("%s\n", step[][]);
}
}
void dfs(int p, int q, int pos){
while (p <= q){
if (s[p][pos] != '#' && s[p][pos] != '*'){
if (pos == ){
printf("%s\n", s[p]);
}
else{
printf("%s\n%s\n%s\n", step[][], s[p] + pos, step[][]);
}
p++;
continue;
}
int i;
bool flag = false;
for (i = p + ; i <= q; i++){
if (s[i][pos] == s[p][pos]){
flag = true;
}
else{
break;
}
}
i--;
if (flag == true){
display(s[p][pos], , pos);
dfs(p, i, pos + );
display(s[p][pos], , pos);
p = i + ;
}
else{
if (pos == ){
printf("%s\n", s[p]);
}
else{
printf("%s\n%s\n%s\n", step[][], s[p] + pos, step[][]);
}
p++;
}
}
}
int main()
{
#ifdef OPEN_FILE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
m = ;
while (~scanf("%s", s[m])){
m++;
}
m--;
dfs(, m, );
//printf("%d\n", m);
}
SGU 461 Wiki Lists dfs的更多相关文章
- itemscope itemtype="http://schema.org/AggregateRating"
Review Canonical URL: http://schema.org/Review Thing > CreativeWork > Review A review of an it ...
- sgu 125 Shtirlits dfs 难度:0
125. Shtirlits time limit per test: 0.25 sec. memory limit per test: 4096 KB There is a checkered fi ...
- sgu 321 The Spy Network (dfs+贪心)
321. The Spy Network Time limit per test: 0.5 second(s)Memory limit: 65536 kilobytes input: standard ...
- SGU 455 Sequence analysis(Cycle detection,floyd判圈算法)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operati ...
- 深度优先搜索(DFS)
定义: (维基百科:https://en.wikipedia.org/wiki/Depth-first_search) 深度优先搜索算法(Depth-First-Search),是搜索算法的一种.是沿 ...
- [转]http://lua-users.org/wiki/LpegTutorial
Simple Matching LPeg is a powerful notation for matching text data, which is more capable than Lua s ...
- (转)The AlphaGo Replication Wiki
The AlphaGo Replication Wiki 摘自:https://github.com/Rochester-NRT/RocAlphaGo/wiki/01.-Home Contents : ...
- 树形DP求树的重心 --SGU 134
令一个点的属性值为:去除这个点以及与这个点相连的所有边后得到的连通分量的节点数的最大值. 则树的重心定义为:一个点,这个点的属性值在所有点中是最小的. SGU 134 即要找出所有的重心,并且找出重心 ...
- Codeforces Round #374 (Div. 2) A B C D 水 模拟 dp+dfs 优先队列
A. One-dimensional Japanese Crossword time limit per test 1 second memory limit per test 256 megabyt ...
随机推荐
- Springboot+swagger2的接口文档开发
一.创建一个SpringBoot项目 1. 2. 3. 4. 把web里的web选中,SQL里选择自己需要的,点击next 二.创建各项所需的controller,configure等 1. 项目布局 ...
- 【codeforces 29B】Traffic Lights
[题目链接]:http://codeforces.com/problemset/problem/29/B [题意] 一辆车; 让从A开到B; 然后速度是v; (只有在信号灯前面才能停下来..否则其他时 ...
- Java NIO笔记(一):NIO介绍
Java NIO即Java Non-blocking IO(Java非堵塞I/O),由于是在Jdk1.4之后添加的一套新的操作I/O工具包,所以通常会被叫做Java New IO.NIO是为提供I/O ...
- iOS:UISplitViewController的创建
UISplitViewController是iPad特有的系统方法,主要效果就是呈现iPad的经典切割界面 代码创建实例: - (BOOL)application:(UIApplication *)a ...
- 蓝牙压力測试报抛android.os.TransactionTooLargeException异常分析总结
1.从main日志中找到异常点,例如以下: 08-20 11:05:19.754 5023 5023 E AndroidRuntime: FATAL EXCEPTION: main 08-20 11: ...
- Vim 批量替换
假设在非Win系统下. 想批量替换文本不再是Ctrl+F那么简单了, 一般用Vim来做批量替换, 略微复杂点: 比如将192.168.0.1替换为192.168.0.2 :%s/192.168.0.1 ...
- [leetcode][math] Add Digits
题目: Given a non-negative integer num, repeatedly add all its digits until the result has only one di ...
- POJ 3256 Cow Picnic
Cow Picnic Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4928 Accepted: 2019 Descri ...
- String methods
A method is similar to a function – it takes arguments and returns a value – but the syntax is diffe ...
- OpenGL的前世和今生
这并不是一个恰当的题目,因为我主要想说的是OpenGL的今生,基于OpenGL3.x一种更现代化的方式.但是把前世和今生放在一起在语言上更加连贯,而且适当的了解过去,会帮助理解现在的OpenGL,以一 ...