Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <string>
- #include <cctype>
- #include <cstdlib>
- #define N 1005
- #define M 2011
- using namespace std;
- string s, sum;
- int in[N][N];
- int y, x, color = 1;
- int print[M][M];
- void f(string tag) {
- if (tag[1] == '/') {
- return;
- }
- if (tag == "<table>")
- return;
- if (tag == "<tr>") {
- y++;
- x = 0;
- while (in[y][x])
- x++;
- return;
- }
- if (tag == "<td>") {
- if (in[y][x]) {
- puts("ERROR");
- exit(0);
- }
- in[y][x] = color++;
- x++;
- return;
- }
- int row = 1, col = 1;
- if (tag[3] == 'c') {
- tag = tag.substr(12);
- if (tag[1] == '0') {
- tag = tag.substr(3);
- col = 10;
- }
- else {
- tag = tag.substr(2);
- col = int(tag[0] - '0');
- }
- if (tag[0] == 'r') {
- tag = tag.substr(10);
- if (tag[1] == '0') {
- tag = tag.substr(3);
- row = 10;
- }
- else {
- tag = tag.substr(2);
- row = int(tag[0] - '0');
- }
- }
- }
- else {
- tag = tag.substr(12);
- if (tag[1] == '0') {
- tag = tag.substr(3);
- row = 10;
- }
- else {
- tag = tag.substr(2);
- row = int(tag[0] - '0');
- }
- if (tag[0] == 'c') {
- tag = tag.substr(10);
- if (tag[1] == '0') {
- tag = tag.substr(3);
- col = 10;
- }
- else {
- tag = tag.substr(2);
- col = int(tag[0] - '0');
- }
- }
- }
- for (int i = x; i < x + col; i++)
- for (int j = y; j < y + row; j++)
- if (in[j][i]) {
- puts("ERROR");
- exit(0);
- }
- else {
- in[j][i] = color;
- }
- color++;
- }
- int main() {
- freopen("table.in", "r", stdin);
- freopen("table.out", "w", stdout);
- while (cin >> s) {
- sum += s;
- }
- for (int i = 0; i < sum.size(); i++)
- if (isupper(sum[i]))
- sum[i] = tolower(sum[i]);
- s = "";
- for (int i = 0; i < sum.size(); ) {
- int pos;
- s += sum[i];
- if (sum[i] == '>')
- for (int j = i + 1; j < sum.size(); j++)
- if (sum[j] == '<') {
- i = j - 1;
- break;
- }
- i++;
- }
- sum = "";
- bool add = false;
- for (int j = s.size() - 1; j >= 0; j--) {
- if (s[j] == '>')
- add = true;
- if (add)
- sum = s[j] + sum;
- }
- cout << sum << endl;
- for (int i = 0; i < sum.size(); ) {
- for (int j = i + 1; ; j++)
- if (sum[j] == '>') {
- string tag = sum.substr(i, j - i + 1);
- f(tag);
- i = j + 1;
- break;
- }
- }
- for (int i = 0; i < N; i++) {
- int j = 0, k;
- while (!in[i][j]) j++;
- int w;
- for (k = j; k < N; k++) {
- if (!in[i][k]) {
- break;
- }
- w++;
- }
- j = k + 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement