Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <cstring>
  4. /*
  5. • сдвинуться на клетку вверх - U;
  6. • сдвинуться на клетку вниз - D;
  7. • сдвинуться на клетку влево - L;
  8. • сдвинуться на клетку вправо - R;
  9. */
  10.  
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15.     char ** matrix = new char *[2200];
  16.     for (int i = 0; i < 2200; i++)
  17.     {
  18.         matrix[i] = new char[2200];
  19.         for (int j = 0; j < 2200; j++)
  20.             matrix[i][j] = '0';
  21.     }
  22.  
  23.     int posY = 1099; int posX = 1099;
  24.     int r = 0;
  25.  
  26.     matrix[1099][1099] = '1';
  27.     char ch = '0';
  28.     char * str = new char[1001];
  29.     scanf("%s", str);
  30.     for (int i = 0; i < strlen(str); i++)
  31.     {
  32.         ch = str[i];
  33.  
  34.         if (ch == 'U')
  35.         {
  36.             posY++;
  37.             if (matrix[posX][posY] == '2') continue;
  38.             if (matrix[posX][posY] == '1')
  39.             {
  40.                 r++;
  41.                 matrix[posX][posY] = '2';
  42.             }
  43.             else if (matrix[posX][posY] == '0')
  44.             {
  45.    
  46.                 matrix[posX][posY] = '1';
  47.             }
  48.         }
  49.         else if (ch == 'D')
  50.         {
  51.             posY--;
  52.             if (matrix[posX][posY] == '2') continue;
  53.             if (matrix[posX][posY] == '1')
  54.             {
  55.                 r++;
  56.                 matrix[posX][posY] = '2';
  57.             }
  58.             else if (matrix[posX][posY] == '0')
  59.             {
  60.  
  61.                 matrix[posX][posY] = '1';
  62.             }
  63.         }
  64.         else if (ch == 'L')
  65.         {
  66.             posX++;
  67.             if (matrix[posX][posY] == '2') continue;
  68.             if (matrix[posX][posY] == '1')
  69.             {
  70.                 r++;
  71.                 matrix[posX][posY] = '2';
  72.             }
  73.             else if (matrix[posX][posY] == '0')
  74.             {
  75.  
  76.                 matrix[posX][posY] = '1';
  77.             }
  78.         }
  79.         else if (ch == 'R')
  80.         {
  81.             posX--;
  82.             if (matrix[posX][posY] == '2') continue;
  83.             if (matrix[posX][posY] == '1')
  84.             {
  85.                 r++;
  86.                 matrix[posX][posY] = '2';
  87.             }
  88.             else if (matrix[posX][posY] == '0')
  89.             {
  90.  
  91.                 matrix[posX][posY] = '1';
  92.             }
  93.         }
  94.     }
  95.  
  96.  
  97.    
  98.  
  99.     std::cout << r << std::endl;
  100.  
  101.     //system("pause");
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement