Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int n,m;
- cin>>n>>m;
- char a[n][m];
- for(int i=0;i<n;i++)
- for(int j=0;j<m;j++)
- a[i][j]='.';
- string commands;
- cin>>commands;
- int dot_now_x = 0;
- int dot_now_y = 0;
- cout<<commands.length()<<"\n";
- for(int i=0;i<commands.length();i++){
- if(commands[i]=='<' or commands[i]=='^' or commands[i]=='v' or commands[i]=='>')
- switch (commands[i]){
- case '>':
- if(dot_now_x+1 < m) dot_now_x++;
- break;
- case '<':
- if(dot_now_x-1 >= 0) dot_now_x--;
- break;
- case 'v':
- if(dot_now_y+1 < n) dot_now_y++;
- break;
- case '^':
- if(dot_now_y-1>= 0) dot_now_y--;
- break;
- default: break;
- }
- else
- a[dot_now_y][dot_now_x]=commands[i];
- }
- for(int i=0;i<n;i++){
- for(int j=0;j<m;j++)
- cout<<a[i][j];
- cout<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement