TAB

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.

Wednesday 27 January 2016

PRACTICE PROBLEM 2 :(24-1 to 31-1) :'L' Pattern

======================================================================== #include<stdio.h>
void main()
{
int i,j;
int r,c;
scanf("%d %d",&r,&c);
char a[r][c];
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf(" %c",&a[i][j]);
int check=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
int x,y;
x=i;
y=j;
int up,right;
up=0;
right=0;
//ANALYSING
while(x>0)
{
//printf("checking up\n");
x--;
if(a[x][y]==a[i][j])
up++;
else
break;
}
x=i;
while(y<c)
{
//printf("checking right\n");
y++;
if(a[x][y]==a[i][j])
right++;
else
break;
}
//printf("%d %d",up,right);
if(up!=0 && up==right)
{
printf("Yes");
check=1;break;
}
}
if(check==1)
{break;}
}
if(check==0)
printf("No");
}

16 comments:

  1. the initial values of x and y are 0 then how is the programme running further? :/

    ReplyDelete
    Replies
    1. No , i initialize the values of x and y to be i and j respectively ,thus the program runs.(lines 17 and 18).

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. The nested for loop cannot be avoided in order to access each element.Yes , i know i could have made a much faster program by replacing the while loops with a single if statement,but i wanted to show the concept of traversing the columns and rows of each element as it is used in many pattern recognition problems.(Ex:8 Queen problem)

      Delete
  3. HOW Can you give variable indexes in the array declaration
    plz check line no. 7 of this code,where you have declared
    a 2-d character array as

    char a[r][c];

    ReplyDelete
    Replies
    1. Yes it is valid as long as r and c have integer values. It compiled when I checked.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. I think there are compiler-specific extensions that allow such a thing. You might as well use this feature rather than allocate dynamically which may complicate things.

      Delete
  4. U should use fflush(stdin) before every character or string input using scanf() because while pressing enter the compiler interprets the "enter" as a character literal and leads to unexpected results. Its required to flush the input buffer and it should be placed in j loop when entering the colour of coin from user.

    ReplyDelete
    Replies
    1. The space before the %c is used for the same purpose.Its not as efficient but does the work!

      Delete
  5. This comment has been removed by the author.

    ReplyDelete
  6. include { after the first for loop bro in the 9th line and a closing } in the 10th line. :)

    ReplyDelete
    Replies
    1. If there is only a single statement((in this case the scanf) to be executed inside the for loop,we can avoid using the parenthesis.

      Delete