Guest User

Untitled

a guest
Oct 10th, 2014
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <ctime>
  4. #include <string>
  5. #include <vector>
  6. #include <cstdio>
  7.  
  8. using namespace std;
  9.  
  10. vector<string> V;
  11.  
  12. void process(int from, int to, int idx, bool inside) {
  13.   int nf = -1;
  14.   for (int i = from; i <= to; i++) {
  15.     char c = V[i][idx];
  16.     if ((c != '*' && c != '#') || (i == to || V[i+1][idx] != c)) {
  17.       if (nf != -1) {
  18.         if (V[nf][idx] == '*') {
  19.           if (inside) { cout << "<li>" << endl; }
  20.           cout << "<ul>" << endl;
  21.           process(nf, i, idx+1, true);
  22.           cout << "</ul>" << endl;
  23.           if (inside) { cout << "</li>" << endl; }
  24.         } else {
  25.           if (inside) { cout << "<li>" << endl; }
  26.           cout << "<ol>" << endl;
  27.           process(nf, i, idx+1, true);
  28.           cout << "</ol>" << endl;
  29.           if (inside) { cout << "</li>" << endl; }
  30.         }
  31.         nf = -1;
  32.       } else {
  33.         if (inside) { cout << "<li>" << endl; }
  34.         cout << V[i].substr(idx) << endl;
  35.         if (inside) { cout << "</li>" << endl; }
  36.       }
  37.     } else if (nf == -1) {
  38.       nf = i;
  39.     }
  40.   }
  41.   if (nf != -1) {
  42.     if (V[nf][idx] == '*') {
  43.       if (inside) { cout << "<li>" << endl; }
  44.       cout << "<ul>" << endl;
  45.       process(nf, to, idx+1, true);
  46.       cout << "</ul>" << endl;
  47.       if (inside) { cout << "</li>" << endl; }
  48.     } else {
  49.       if (inside) { cout << "<li>" << endl; }
  50.       cout << "<ol>" << endl;
  51.       process(nf, to, idx+1, true);
  52.       cout << "</ol>" << endl;
  53.       if (inside) { cout << "</li>" << endl; }
  54.     }
  55.     nf = -1;
  56.   }
  57. }
  58.  
  59. int main(void) {
  60.   string line;
  61.   freopen("input.txt", "rt", stdin);
  62.   freopen("output.txt", "wt", stdout);
  63.   while(getline(cin,line)) {
  64.     V.push_back(line);
  65.   }
  66.   process(0,(int)V.size()-1,0,false);
  67.   return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment