Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <ctime>
- #include <string>
- #include <vector>
- #include <cstdio>
- using namespace std;
- vector<string> V;
- void process(int from, int to, int idx, bool inside) {
- int nf = -1;
- for (int i = from; i <= to; i++) {
- char c = V[i][idx];
- if ((c != '*' && c != '#') || (i == to || V[i+1][idx] != c)) {
- if (nf != -1) {
- if (V[nf][idx] == '*') {
- if (inside) { cout << "<li>" << endl; }
- cout << "<ul>" << endl;
- process(nf, i, idx+1, true);
- cout << "</ul>" << endl;
- if (inside) { cout << "</li>" << endl; }
- } else {
- if (inside) { cout << "<li>" << endl; }
- cout << "<ol>" << endl;
- process(nf, i, idx+1, true);
- cout << "</ol>" << endl;
- if (inside) { cout << "</li>" << endl; }
- }
- nf = -1;
- } else {
- if (inside) { cout << "<li>" << endl; }
- cout << V[i].substr(idx) << endl;
- if (inside) { cout << "</li>" << endl; }
- }
- } else if (nf == -1) {
- nf = i;
- }
- }
- if (nf != -1) {
- if (V[nf][idx] == '*') {
- if (inside) { cout << "<li>" << endl; }
- cout << "<ul>" << endl;
- process(nf, to, idx+1, true);
- cout << "</ul>" << endl;
- if (inside) { cout << "</li>" << endl; }
- } else {
- if (inside) { cout << "<li>" << endl; }
- cout << "<ol>" << endl;
- process(nf, to, idx+1, true);
- cout << "</ol>" << endl;
- if (inside) { cout << "</li>" << endl; }
- }
- nf = -1;
- }
- }
- int main(void) {
- string line;
- freopen("input.txt", "rt", stdin);
- freopen("output.txt", "wt", stdout);
- while(getline(cin,line)) {
- V.push_back(line);
- }
- process(0,(int)V.size()-1,0,false);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment