Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdio>
- #include<utility>
- using namespace std;
- int cheakDirection(int value){
- if(value == 9)
- value = 0; // N
- else if(value == 8)
- value = 1; // O
- else if(value == 7)
- value = 2; // S
- else if(value == 6)
- value = 3; // L
- return value;
- }
- pair<int,int> pointStart(int arr[100][100],int n ,int m){
- pair<int,int> start;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++){
- if( arr[i][j] == 9 ||
- arr[i][j] == 7 ||
- arr[i][j] == 8 ||
- arr[i][j] == 6)
- start = make_pair(i,j);
- }
- }
- return start;
- }
- int robot(char path[],int arr[100][100],int x,int y,int n,int m){
- int dir = cheakDirection(arr[x][y]);
- cout << "dir=" << dir << endl;
- int count = 0;
- for (int i = 0; path[i]; i++) {
- char move = path[i];
- if (move == 'D')
- dir = (dir + 1) % 4;
- else if (move == 'E')
- dir = (4 + dir - 1) % 4;
- else if(move == 'F'){
- // N
- if (dir == 0){
- printf("S0\n");
- x--;
- if(x < 0)
- x = 0;
- if(arr[x][y] == 1){
- printf("if1\n");
- x++;
- }
- else if(arr[x][y] == 2){
- printf("if2\n");
- count++;
- }
- }
- // O
- else if (dir == 1 ) {
- printf("S1\n");
- y++;
- if(y > m)
- y = m-1;
- if(arr[x][y] == 1){
- printf("if1\n");
- y--;
- }
- else if(arr[x][y] == 2){
- printf("if2\n");
- count++;
- }
- }
- // S
- else if (dir == 2 ){
- printf("S2\n");
- x++;
- if(x> n)
- x = n-1;
- if(arr[x][y] == 1){
- printf("if1\n");
- x--;
- }
- else if(arr[x][y] == 2){
- printf("if2\n");
- count++;
- }
- }
- // L
- else if(dir == 3 ){
- printf("S3\n");
- y--;
- if(y < 0)
- y = 0;
- if(arr[x][y] == 1){
- printf("if1\n");
- y++;
- }
- else if(arr[x][y] == 2){
- printf("if2\n");
- count++;
- }
- }
- }
- printf("x=%d y=%d count=%d\n",x,y,count);
- }
- return count;
- }
- void out(int arr[100][100],int n,int m){
- for(int i=0;i<n;i++){
- for(int j=0;j<m;j++){
- cout << arr[i][j] <<" ";
- }
- cout << endl;
- }
- }
- int main()
- {
- int n,m,s;
- char mes;
- while(cin >> n >> m >> s ){
- if (n==0 && m==0 && s==0) break;
- int screen[100][100];
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- cin >> mes;
- if(mes == '.')
- screen[i][j] = 0;
- else if (mes == '#')
- screen[i][j] = 1;
- else if (mes == '*')
- screen[i][j] = 2;
- else if (mes == 'N')
- screen[i][j] = 9;
- else if (mes == 'S')
- screen[i][j] = 8;
- else if (mes == 'L')
- screen[i][j] = 7;
- else if (mes == 'O')
- screen[i][j] = 6;
- }
- }
- out(screen,n,m);
- char path[]="FDFFFFFFEEFFFFFFEFDF";
- pair<int,int> p = pointStart(screen,n,m);
- printf("start =%d %d",p.first,p.second);
- cout <<"robot "<< robot(path,screen,p.first,p.second,n,m) << endl;
- //out(screen,n,m);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment