Find Co-ordinates - Other Side

 Coding Problem Keys 

 Find Co-ordinates - Other Side 

 Problem Statement 

The co-ordinates of two corners of a rectangle representing the bottom or the left are given as the input. The area A of the rectangle is also passed as the input. The program must print the co-ordinates of the other two corners. (Assume the edges of the rectangle are always parallel to x-axis or y-axis).

 Boundary Condition(s) 

-1000 <= x, y co-ordinates <= 1000
1 <= A <= 1000000

 Input Format 

The first line contains the co-ordinates of the first corner.
The second line contains the co-ordinates of the second corner.
The third line contains A.

 Output Format 

The first line contains the co-ordinates of the third corner.
The second line contains the co-ordinates of the fourth corner.

 Example Input/Output 1 

 Input 

0 0
0 5
30

 Output 

6 0
6 5

 Explanation 

Length is 5. The area is 30. Hence breadth is 30/5 = 6. Based on that the other two co-ordinates are calculated.

 Example Input/Output 2 

 Input 

2 5
10 5
24

 Output 

2 8
10 8

 Example Input/Output 3 

 Input 

3 -5
-2 -5
25

 Output 

3 0
-2 0

 Note: Max Execution Time Limit: 50 millisecs 

 Solution 

 Programming Language: C Language 

#include<stdio.h>
#include<stdlib.h>
int main(){
    int x1,x2,y1,y2,a;
    scanf("%d %d %d %d %d",&x1,&y1,&x2,&y2,&a);
    int l=sqrt(pow(x2-x1,2)+pow(y2-y1,2)),b=a/l;
    if(x1==x2){printf("%d %d\n%d %d",x1+b,y1,x2+b,y2);}
    else{printf("%d %d\n%d %d",x1,y1+b,x2,y2+b);}
}
//Published By PKJCODERS

 Alter 

#include<stdio.h>
#include<stdlib.h>
int main(){
    int x1,y1,x2,y2,area,diff;
    scanf("%d %d\n%d %d\n%d\n",&x1,&y1,&x2,&y2,&area);
    if(y1==y2){
        diff=abs(x1-x2);
        diff=area/diff;
        printf("%d %d\n%d %d\n",x1,diff+y1,x2,diff+y2);
    }else{
        diff=abs(y1-y2);
        diff=area/diff;
        printf("%d %d\n%d %d\n",diff+x1,y1,diff+x2,y2);
    }
}
//Published By PKJCODERS

 Programming Language: C++ Language 

#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv)
{
    int x1,x2,y1,y2,a;cin>>x1>>y1>>x2>>y2>>a;
    int d1,d2,d3;
    d1=((x2)-(x1))*((x2)-(x1));
    d2=((y2)-(y1))*((y2)-(y1));
    d3=sqrt(d1 + d2);
    if(x2!=x1)cout<<x1<<" "<<y1+a/d3<<endl<<x2<<" "<<y2+a/d3;
    if(x2==x1)cout<<a/d3+x1<<" "<<y1<<endl<<a/d3+x2<<" "<<y2;
}
//Published By PKJCODERS

Alter 

#include <bits/stdc++.h>
using namespace std;
int main(int argc,char** argv){
    int x1,y1,x2,y2,area;
    cin>>x1>>y1>>x2>>y2>>area;
    if(x1==x2){
        int val=area/abs(y1-y2);
        cout<<x1+val<<" "<<y1<<endl;
        cout<<x2+val<<" "<<y2<<endl;
    }else{
        int val = area/(abs(x1-x2));
        cout<<x1<<" "<<y1+val<<endl;
        cout<<x2<<" "<<y2+val<<endl;
    }
}
//Published By PKJCODERS

 Programming Language: Java Language 

import java.util.*;
public class Hello {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
        int x1 = sc.nextInt(), x2 = sc.nextInt(), y1 = sc.nextInt(), y2 = sc.nextInt(), area = sc.nextInt(), sideToAdd;
	if(x1 == y1){
	    sideToAdd = area / (Math.max(x2,y2) - Math.min(x2,y2));
	    System.out.printf("%d %d\n%d %d",x1+sideToAdd, x2, y1+sideToAdd, y2);
	}else{
	    sideToAdd = area / (Math.max(x1,y1) - Math.min(x1,y1));
	    System.out.printf("%d %d\n%d %d",x1, x2+sideToAdd, y1, y2+sideToAdd);
	}
    }
}
//Published By PKJCODERS

 Alter 

import java.util.*;
public class Hello {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int X1=sc.nextInt(),Y1=sc.nextInt();
	int X2=sc.nextInt(),Y2=sc.nextInt();
	int A=sc.nextInt();
	if(Y1==Y2){
	    int L=Math.abs(X1-X2);
	    int B=A/L;
	    System.out.println(X1+" "+(Y1+B));
	    System.out.println(X2+" "+(Y2+B));
	}else{
	    int B=Math.abs(Y1-Y2);
	    int L=A/B;
	    X1+=L;X2+=L;
	    System.out.println(X1+" "+Y1);
	    System.out.println(X2+" "+Y2);
	}
    }
}
//Published By PKJCODERS

 Programming Language: Python 3 Language 

P1=list(map(int,input().split()))
P2=list(map(int,input().split()))
A=int(input())
if P1[0]==P2[0]:
    L=A//abs(P1[1]-P2[1])
    print("{} {}\n{} {}".format(P1[0]+L,P1[1],P2[0]+L,P2[1]))
else:
    L=A//abs(P1[0]-P2[0])
    print("{} {}\n{} {}".format(P1[0],L+P1[1],P2[0],L+P2[1]))
#Published By PKJCODERS

 Alter 

a,b=map(int,input().split())
c,d=map(int,input().split())
x=int(input())
if a==c:
    a=c=(a+(x//abs(b-d)))
    print(a,b)
    print(c,d)
elif b==d:
    b=d=(b+(x//abs(a-c)))
    print(a,b)
    print(c,d)
#Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Unique Characters

Difference between a number and it's reverse

String - Special Characters

Reverse Array

Matrix Diagonal Pattern

Vowels Count