সুবিন ভাইয়ের রোবট সমস্যাটি সমাধানে কেউ সাহায্য করুন। ব্লক্‌ড সেলের পর এক ঘর অটো শিফট হচ্ছে।

#include<stdio.h>
int main()
{
    int grid [10][10];
    char c;
    int i,j,x,y,n;

    for(i=0;i<10;i++){
        for(j=0;j<10;j++){
            grid[i][j]=1;
        }
    }
    printf("Please enter the number of blocked cells: ");
    scanf("%d",&n);

    printf("Now enter the the cells: ");
    for(i=0;i<n;i++){
        scanf("%d %d",&x,&y);
        grid[x][y]=0;
    }
    printf("Please enter the initial position: \n");
    scanf("%d %d",&x,&y);
    printf("Move it");
    while(1){
        if(x>=0 && x<10 && y>=0 && y<10 && grid[x][y]==1){
            scanf("%c",&c);
            if(c=='S'){
                break;
            }
            else if(c=='U'){
                x--;
            }
            else if(c=='D'){
                x++;
            }
            else if(c=='R'){
                y++;
            }
            else if(c=='L'){
                y--;
            }
        }
        else if(grid[x][y]==0) {
            printf("the cell is blocked");
            if(c=='S'){
                break;
            }
            else if(c=='U'){
                x--;
            }
            else if(c=='D'){
                x++;
            }
            else if(c=='R'){
                y++;
            }
            else if(c=='L'){
                y--;
            }
        }
    }
    printf("Final position of the robot is : %d, %d\n",x,y);
    return 0;
}

asked 18 Oct, 21:11

Sayem's gravatar image

Sayem
212

edited 19 Oct, 15:18

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×395
×1

question asked: 18 Oct, 21:11

question was seen: 318 times

last updated: 19 Oct, 15:18