Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <cstring>
- /*
- • сдвинуться на клетку вверх - U;
- • сдвинуться на клетку вниз - D;
- • сдвинуться на клетку влево - L;
- • сдвинуться на клетку вправо - R;
- */
- using namespace std;
- int main()
- {
- char ** matrix = new char *[2200];
- for (int i = 0; i < 2200; i++)
- {
- matrix[i] = new char[2200];
- for (int j = 0; j < 2200; j++)
- matrix[i][j] = '0';
- }
- int posY = 1099; int posX = 1099;
- int r = 0;
- matrix[1099][1099] = '1';
- char ch = '0';
- char * str = new char[1001];
- scanf("%s", str);
- for (int i = 0; i < strlen(str); i++)
- {
- ch = str[i];
- if (ch == 'U')
- {
- posY++;
- if (matrix[posX][posY] == '2') continue;
- if (matrix[posX][posY] == '1')
- {
- r++;
- matrix[posX][posY] = '2';
- }
- else if (matrix[posX][posY] == '0')
- {
- matrix[posX][posY] = '1';
- }
- }
- else if (ch == 'D')
- {
- posY--;
- if (matrix[posX][posY] == '2') continue;
- if (matrix[posX][posY] == '1')
- {
- r++;
- matrix[posX][posY] = '2';
- }
- else if (matrix[posX][posY] == '0')
- {
- matrix[posX][posY] = '1';
- }
- }
- else if (ch == 'L')
- {
- posX++;
- if (matrix[posX][posY] == '2') continue;
- if (matrix[posX][posY] == '1')
- {
- r++;
- matrix[posX][posY] = '2';
- }
- else if (matrix[posX][posY] == '0')
- {
- matrix[posX][posY] = '1';
- }
- }
- else if (ch == 'R')
- {
- posX--;
- if (matrix[posX][posY] == '2') continue;
- if (matrix[posX][posY] == '1')
- {
- r++;
- matrix[posX][posY] = '2';
- }
- else if (matrix[posX][posY] == '0')
- {
- matrix[posX][posY] = '1';
- }
- }
- }
- std::cout << r << std::endl;
- //system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement