ccf-201512-3

ccf-201512-3

#include <iostream>
using namespace std;
char a[101][101];
int m, n, q, f, x1, y1, x2, y2;
char s;
void com(int &a, int &b) {
  if (a > b) {
    a = a + b;
    b = a - b;
    a = a - b;
  }
}
void line(int x1, int y1, int x2, int y2) {
  int b = x2 - x1;
  //    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
  com(x1, x2);
  com(y1, y2);
  for (int i = x1; i < x2 + 1; i++) {
    for (int j = y1; j < y2 + 1; j++) {
      if (b == 0) {
        if (a[j][i] == '-' || a[j][i] == '+') {
          a[j][i] = '+';
        } else {
          a[j][i] = '|';
        }
      } else {
        if (a[j][i] == '|' || a[j][i] == '+') {
          a[j][i] = '+';
        } else {
          a[j][i] = '-';
        }
      }
    }
  }
}
void fill(int x1, int y1, char s) {
  if (a[y1][x1] != '-' && a[y1][x1] != '|' && a[y1][x1] != '+' &&
      a[y1][x1] != s && x1 > -1 && x1 < m && y1 > -1 && y1 < n) {
    a[y1][x1] = s;
  } else {
    return;
  }
  fill(x1 + 1, y1, s);
  fill(x1 - 1, y1, s);
  fill(x1, y1 + 1, s);
  fill(x1, y1 - 1, s);
}
int main() {
  cin >> m >> n >> q;
  for (int i = n; i > -1; i--) {
    for (int j = 0; j < m + 1; j++) {
      a[i][j] = '.';
    }
  }
  for (int k = 0; k < q; k++) {
    cin >> f;
    if (f == 0) {
      cin >> x1 >> y1 >> x2 >> y2;
      line(x1, y1, x2, y2);
    } else {
      cin >> x1 >> y1 >> s;
      fill(x1, y1, s);
    }
  }
  for (int i = n - 1; i > -1; i--) {
    for (int j = 0; j < m - 1; j++) {
      cout << a[i][j];
    }
    cout << a[i][m - 1] << endl;
  }
  return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36792042/article/details/82456367