Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define OPEN 0
- #define CLOSE 1
- #define MAXL 1001
- using namespace std;
- string mat[MAXL]; int N;
- inline string item_tag(char t, bool closing) {
- if (t != '*' && t != '#') return "";
- string tag = "<";
- if (closing) tag += "/";
- return tag+"li>\n";
- }
- inline string list_tag(char t, bool closing) {
- if (t != '*' && t != '#') return "";
- string tag = "<";
- if (closing) tag += "/";
- return tag+((t == '#') ? "ol" : "ul")+">\n";
- }
- string parse(char type, int beg, int end, int pos) {
- string res = "", aux;
- if (beg == end) {
- res = mat[beg].substr(pos-1);
- if (res != "") res +="\n";
- return res;
- }
- int interval_begin = -1;
- char curr = '!';
- for (int i=beg; i<=end; i++) {
- if (mat[i][pos] != '*' && mat[i][pos] != '#') {
- if (interval_begin != -1) {
- aux = parse(curr, interval_begin, i-1, pos+1);
- if (aux != "") res += item_tag(type, OPEN) + aux + item_tag(type, CLOSE);
- }
- aux = mat[i].substr(pos);
- if (aux != "") res += item_tag(type, OPEN)+aux+"\n"+item_tag(type, CLOSE);
- interval_begin = -1; curr = '!';
- } else if (mat[i][pos] != curr) {
- if (interval_begin != -1) {
- aux = parse(curr, interval_begin, i-1, pos+1);
- if (aux != "") res += item_tag(type, OPEN)+aux+item_tag(type, CLOSE);
- }
- interval_begin = i; curr = mat[i][pos];
- }
- }
- if (interval_begin != -1) {
- aux = parse(curr, interval_begin, end, pos+1);
- if (aux != "") res += item_tag(type, OPEN) + aux + item_tag(type, CLOSE);
- }
- if (res != "") res = list_tag(type, OPEN)+res+list_tag(type, CLOSE);
- return res;
- }
- int main() {
- #ifdef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int words=0;
- while (getline(cin, mat[words]))
- words++;
- cout << parse('!', 0, words-1, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement