Untitled

 avatar
unknown
plain_text
5 months ago
2.7 kB
2
Indexable
#include <iostream>
#include <string>
#include <vector>

using namespace std;



int main() 
{
    bool cont = true;
    int rows, columns;
    int a, b, c, d, y, x;
    char board[25][25];
    vector<char> copiedBoard;
    string command;
    char p;


    cin >> command;
    cin >> rows;
    cin >> columns;

    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < columns; j++)
        {
            cin >> board[i][j];
        }
    }


    while (cont) 
    {
        cin >> command;

        if (command == "PRT")
        {

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    cout << board[i][j];
                }
                cout << endl;
            }
            cout << endl;
        }
        else if (command == "END")
        {

            cont = false;
        }
        else if (command == "COPY")
        {

            copiedBoard.clear();

            cin >> a;
            cin >> b;
            cin >> c;
            cin >> d;

            for (int i = a; i <= c; i++)
            {
                for (int j = b; j <= d; j++)
                {
                    copiedBoard.push_back(board[i][j]);
                }
                copiedBoard.push_back('\n');
            }
        }
        else if (command == "PASTE")
        {

            cin >> y;
            cin >> x;

            if (copiedBoard.empty())
            {
                cout << "ERROR" << endl;
            }
            else
            {
                int counter = 0;
                for (int i = y; i < rows && counter < copiedBoard.size(); i++)
                {
                    for (int j = x; j < columns && copiedBoard[counter] != '\n'; j++)
                    {
                        board[i][j] = copiedBoard[counter++];
                    }
                    counter++;
                }
            }
        }
        else if (command == "DRAW") 
        {
            cin >> y;
            cin >> x;
            cin >> p;
            cin >> d;

            int radiusSquared = d * d;

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    int distSquared = (i - y) * (i - y) + (j - x) * (j - x);
                    if (distSquared <= radiusSquared)
                    {
                        board[i][j] = p;
                    }
                }
            }

        }
    }

    return 0;
}
Editor is loading...
Leave a Comment