Advertisement
Malinovsky239

Untitled

Nov 11th, 2011
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <string>
  4. #include <cctype>
  5. #include <cstdlib>
  6.  
  7. #define N 1005
  8. #define M 2011
  9.  
  10. using namespace std;
  11.  
  12. string s, sum;
  13. int in[N][N];
  14. int y, x, color = 1;
  15. int print[M][M];
  16.  
  17. void f(string tag) {
  18.     if (tag[1] == '/') {
  19.         return;
  20.     }
  21.     if (tag == "<table>")
  22.         return;
  23.     if (tag == "<tr>") {
  24.         y++;
  25.         x = 0;
  26.         while (in[y][x])
  27.             x++;
  28.         return;
  29.     }
  30.     if (tag == "<td>") {
  31.         if (in[y][x]) {
  32.             puts("ERROR");
  33.             exit(0);           
  34.         }
  35.         in[y][x] = color++;    
  36.         x++;       
  37.         return;
  38.     }
  39.     int row = 1, col = 1;
  40.  
  41.     if (tag[3] == 'c') {
  42.         tag = tag.substr(12);
  43.         if (tag[1] == '0') {
  44.             tag = tag.substr(3);
  45.             col = 10;
  46.         }
  47.         else {
  48.             tag = tag.substr(2);
  49.             col = int(tag[0] - '0');
  50.         }
  51.  
  52.         if (tag[0] == 'r') {
  53.             tag = tag.substr(10);
  54.             if (tag[1] == '0') {
  55.                 tag = tag.substr(3);
  56.                 row = 10;
  57.             }
  58.             else {
  59.                 tag = tag.substr(2);
  60.                 row = int(tag[0] - '0');
  61.             }
  62.         }
  63.     }
  64.     else {
  65.         tag = tag.substr(12);
  66.         if (tag[1] == '0') {
  67.             tag = tag.substr(3);
  68.             row = 10;
  69.         }
  70.         else {
  71.             tag = tag.substr(2);
  72.             row = int(tag[0] - '0');
  73.         }
  74.  
  75.         if (tag[0] == 'c') {
  76.             tag = tag.substr(10);
  77.             if (tag[1] == '0') {
  78.                 tag = tag.substr(3);
  79.                 col = 10;
  80.             }
  81.             else {
  82.                 tag = tag.substr(2);
  83.                 col = int(tag[0] - '0');
  84.             }
  85.         }
  86.     }
  87.     for (int i = x; i < x + col; i++)
  88.         for (int j = y; j < y + row; j++)
  89.             if (in[j][i]) {
  90.                 puts("ERROR");
  91.                 exit(0);
  92.             }
  93.             else {
  94.                 in[j][i] = color;
  95.             }
  96.     color++;
  97. }
  98.  
  99. int main() {
  100.     freopen("table.in", "r", stdin);
  101.     freopen("table.out", "w", stdout);
  102.  
  103.     while (cin >> s) {
  104.         sum += s;
  105.     }
  106.  
  107.     for (int i = 0; i < sum.size(); i++)
  108.         if (isupper(sum[i]))
  109.             sum[i] = tolower(sum[i]);
  110.  
  111.     s = "";
  112.     for (int i = 0; i < sum.size(); ) {
  113.         int pos;
  114.         s += sum[i];
  115.         if (sum[i] == '>')
  116.             for (int j = i + 1; j < sum.size(); j++)
  117.                 if (sum[j] == '<') {
  118.                     i = j - 1;
  119.                     break;
  120.                 }
  121.         i++;
  122.     }
  123.     sum = "";
  124.  
  125.     bool add = false;
  126.     for (int j = s.size() - 1; j >= 0; j--) {
  127.         if (s[j] == '>')
  128.             add = true;
  129.         if (add)
  130.             sum = s[j] + sum;
  131.     }
  132.  
  133.     cout << sum << endl;
  134.  
  135.     for (int i = 0; i < sum.size(); ) {
  136.         for (int j = i + 1; ; j++)
  137.             if (sum[j] == '>') {
  138.                 string tag = sum.substr(i, j - i + 1);
  139.                 f(tag);
  140.  
  141.                 i = j + 1;
  142.                 break;
  143.             }      
  144.     }
  145.  
  146.     for (int i = 0; i < N; i++) {
  147.         int j = 0, k;
  148.         while (!in[i][j]) j++;
  149.  
  150.         int w;
  151.         for (k = j; k < N; k++) {
  152.             if (!in[i][k]) {
  153.                 break;
  154.             }          
  155.             w++;
  156.         }
  157.  
  158.         j = k + 1;
  159.     }
  160.  
  161.     return 0;
  162. }
  163.  
  164.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement