Move Grid
Source: codechef
Difficulty: 215

Move Grid
You are located at the coordinate$(0, 0)$on a$2$D grid with perpendicular$X$and$Y$axes.
You will do the following moves:
first,$A$units along positive$X$axis
then,$B$units along positive$Y$axis
then,$C$units along negative$X$axis
finally,$D$units along negative$Y$axis
Find the coordinates of your final position.
Input Format
The first and only line of input contains$4$integers -$A, B, C$and$D$.
Output Format
For each test case, output on a new line the$X$and$Y$coordinates of your final position.
Constraints$1 \le A, B, C, D \le 10$Sample 1:
Explanation:
Initially, you started at$(0, 0)$$5$steps along positive$X$, so you reached$(5, 0)$$4$steps along positive$Y$, so you reached$(5, 4)$$7$steps along negative$X$, so you reached$(-2, 4)$$3$steps along negative$Y$, so you reached$(-2, 1)$Thus, your final position is$(-2, 1)$.
Sample 2:
Input
Output
1 1 1 1
0 0

Sample Input:
5 4 7 3

Sample Output:
-2 1

C++ solution:
#include <bits/stdc++.h>
using namespace std;

int main() {
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<a-c<<" "<<b-d;
}

Go solution:
package main
import "fmt"

func main() {
    var A, B, C, D int
    fmt.Scan(&A, &B, &C, &D)

    finalX := A - C
    finalY := B - D

    fmt.Println(finalX, finalY)
}

Java solution:
import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
    static String MoveGrid(int x,int y,int nx,int ny){
       return (x-nx)+" "+(y-ny);  
    }
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        int y=sc.nextInt();
        int nx=sc.nextInt();
        int ny=sc.nextInt();
        System.out.println(MoveGrid(x,y,nx,ny));

    }
}

JavaScript solution:
// your code goes here
process.stdin.setEncoding('utf-8');

process.stdin.on('data', function(input){
    const [A,B,C,D] = input.trim().split(' ').map(Number);
    
    let X = 0;
    let Y = 0;
    
    for(let i = 0; i<4; i++){
        
        if(i==0){
            X = X + A;
        }else if(i==1){
            Y = Y + B;
        }else if(i==2){
            X = X - C;
        }else{
            Y = Y - D;
        }
    }
    
    console.log(X,Y)
})

Python solution:
# cook your dish here
A,B,C,D=map(int,input().split())
x=A-C
y=B-D
print(x,y)

Ruby solution:
# Read input and split into integers
input = gets.to_s.chomp
a, b, c, d = input.split.map(&:to_i)

# Calculate final position
x_coordinate = a - c
y_coordinate = b - d

# Output the result
puts "#{x_coordinate} #{y_coordinate}"