ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1006. Квадратные рамки

How to read the input?
Послано Myrcella 20 авг 2018 19:36
I found that my program could't deal with ┌┐└┘ correctly. A sample of input is wanted. Please help. Thanks in advance.
Re: How to read the input?
Послано L0ve 20 авг 2018 20:11
I haven't solved this problem yet. The table that you see right after "The frame consists of the following characters:" statement tells you how you should read these special characters.

I tried to generate the sample input, but not sure if it is correct since these are unprintable characters (atleast with my local PC encoding) and I cannot really verify it.

Nevertheless, here is my attempt to generate it. It looks rugged, but that is because of encoding issues. You should probably output it on your own PC with the program below.


..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
...........ÚÄÄÄÄÄ¿................................
...........³.....³................................
....ÚÄÄÄÄÄij.....³..........ÚÄ¿...................
....³......³.....³..........³.³...................
....³......³.....³..........ÀÄÙ...................
....³......³....Ú³ÄÄÄÄ¿.............ÚÄ¿...........
....³......ÀÄÄÄÄÄÙ....³.............³.³...........
....³......³....³.....³.............ÀÄÙ...........
....³......³....³.....³.........ÚÄÄ¿..............
....ÀÄÄÄÄÄÄÙ....³.....³.........³..³..............
................³.....³.........³..³..............
................ÀÄÄÄÄÄÙ.........ÀÄÄÙ..............
..................................................
..................................................


and the program that output it. It reads squares as in output sample and draws a board.


struct square {
  int x, y, a;
  square() = default;
  square(int x, int y, int a) : x(x), y(y), a(a) {}
};

void solve(std::istream &in, std::ostream &out) {
  std::vector<square> squares;
  int n;
  in >> n;
  for (int i = 0; i < n; ++i) {
    int x, y, a;
    in >> x >> y >> a;
    squares.emplace_back(x, y, a);
  }
  unsigned char board[20][50];
  for (int i = 0; i < 20; ++i) {
    for (int j = 0; j < 50; ++j) {
      board[i][j] = '.';
    }
  }
  for (square sq : squares) {
    board[sq.y][sq.x] = 218; // top-left
    board[sq.y][sq.x + sq.a - 1] = 191; // top-right
    board[sq.y + sq.a - 1][sq.x] = 192; // bottom-left
    board[sq.y + sq.a - 1][sq.x + sq.a - 1] = 217; // bottom-right
    for (int x = sq.x + 1; x < sq.x + sq.a - 1; ++x) {
      board[sq.y][x] = 196; // top edge
      board[sq.y + sq.a - 1][x] = 196; // bottom edge
    }
    for (int y = sq.y + 1; y < sq.y + sq.a - 1; ++y) {
      board[y][sq.x] = 179; // left edge
      board[y][sq.x + sq.a - 1] = 179; // right edge
    }
  }
  for (int i = 0; i < 20; ++i) {
    for (int j = 0; j < 50; ++j) {
      out << board[i][j];
    }
    out << '\n';
  }
}


int main() {
  solve(std::cin, std::cout);
}


As for reading it. I think you used char, while you need unsigned char or int for this problem. You can use getchar() that returns int or read into unsigned char s[SIZE]


Edited by author 20.08.2018 20:13

Edited by author 20.08.2018 20:13

Edited by author 20.08.2018 20:13

Edited by author 20.08.2018 20:19

Edited by author 20.08.2018 20:26

Edited by author 20.08.2018 20:34
Re: How to read the input?
Послано Myrcella 20 авг 2018 21:04
Thank you for such long explaination!
I will try it again.
Re: How to read the input?
Послано Myrcella 20 авг 2018 21:08
The problem is solved successfully. Thank you very much!