Advertisement
Jater

Robor_move

Jun 28th, 2021 (edited)
983
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8. int main()
  9. {
  10.     int n,m;
  11.     cin>>n>>m;
  12.     char a[n][m];
  13.     for(int i=0;i<n;i++)
  14.         for(int j=0;j<m;j++)
  15.             a[i][j]='.';
  16.    
  17.     string commands;
  18.     cin>>commands;
  19.     int dot_now_x = 0;
  20.     int dot_now_y = 0;
  21.     cout<<commands.length()<<"\n";
  22.     for(int i=0;i<commands.length();i++){
  23.         if(commands[i]=='<' or commands[i]=='^' or commands[i]=='v' or commands[i]=='>')
  24.             switch (commands[i]){
  25.                 case '>':
  26.                    if(dot_now_x+1 < m) dot_now_x++;
  27.                    break;
  28.                 case '<':
  29.                    if(dot_now_x-1 >= 0) dot_now_x--;
  30.                    break;
  31.                 case 'v':
  32.                    if(dot_now_y+1 < n) dot_now_y++;
  33.                    break;
  34.                 case '^':
  35.                    if(dot_now_y-1>= 0) dot_now_y--;
  36.                    break;
  37.                 default: break;
  38.             }
  39.         else
  40.             a[dot_now_y][dot_now_x]=commands[i];
  41.    }
  42.    
  43.     for(int i=0;i<n;i++){
  44.         for(int j=0;j<m;j++)
  45.             cout<<a[i][j];
  46.         cout<<"\n";
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement