Code For Alls..!

get the code!!

Thursday 7 September 2017

Tower Line of Sight Issue

                                                   Tower Line of Sight Issue
 
       
Four towers A, B, C, D are to be erected. Tower A is to communicate with tower C. Tower B is to communicate with tower D.
Line of sight issue can occur under the following conditions
- when tower B or D is in the straight line connecting A and C
- when tower A or C is in the straight line connecting B and D

The program must accept the co-ordinates of all four towers and print yes or no depending on whether Line of sight issue will occur or not.
Input Format:
The first line will contain X and Y co-ordinates of tower A separated by a space.
The second line will contain X and Y co-ordinates of tower B separated by a space.
The third line will contain X and Y co-ordinates of tower C separated by a space.
The fourth line will contain X and Y co-ordinates of tower D separated by a space
Output Format:
The first line will contain yes or no (smaller case)
Boundary Conditions:
The value of the co-ordinates will be from -500 to 500.
Example Input/Output 1:
0 0
0 -2
2 0
0 2
Output:
yes

Example Input/Output 2:
Input:
0 0
0 -2
2 0
0 -5
Output:
no

c program:

#include<stdio.h>
#include <stdlib.h>
struct p{
    int x,y;
 
}a[4];
int overlap(int p,int b,int c)
{
  if(a[p].x==a[b].x&&a[p].x==a[c].x)
  {
      if(a[b].y>=a[c].y)
      {
          if(a[p].y>=a[c].y&&a[p].y<=a[b].y)
          return 1;
      }
      else if(a[p].y>=a[b].y&&a[p].y<=a[c].y)
      return 1;
  }
  if(a[p].y==a[b].y&&a[p].y==a[c].y)
  {
    if(a[b].x>=a[c].x)
    {
        if(a[p].x>=a[c].y&&a[p].y<=a[b].y)
        return 1;
    }
    else if(a[p].y>=a[b].y&&a[p].y<=a[c].y)
    return 1;
  }
return 0;
 
}
int main()
{
for(int i=0;i<4;i++)
scanf("%d%d",&a[i].x,&a[i].y);
int ls=0;
if(overlap(0,1,3))
ls=1;
else if(overlap(1,0,2))
ls=1;
else if(overlap(2,1,3))
ls=1;
else if(overlap(3,0,2))
ls=1;
if(ls==1)
printf("yes");
else
printf("no");
}                             

No comments:

Post a Comment