Algorithm


Problem Name: beecrowd | 1041
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1041

Coordinates of a Point

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

Write an algorithm that reads two floating values (x and y), which should represent the coordinates of a point in a plane. Next, determine which quadrant the point belongs, or if you are at one of the Cartesian axes or the origin (x = y = 0).

If the point is at the origin, write the message "Origem".

If the point is at X axis write "Eixo X", else if the point is at Y axis write "Eixo Y".

Input

The input contains the coordinates of a point.

Output

The output should display the quadrant in which the point is.

Input Sample Output Sample

4.5 -2.2

Q4

 

0.1 0.1

Q1

 

0.0 0.0

Origem

 

Code Examples

#1 Code Example with C Programming

Code - C Programming



#include <stdio.h>
int main() {
    
    float a,b;
    while (scanf ("%f %f", &a, &b)==2)
        {
        if (a == 0 && b==0) 
            printf("Origem\n");
        else if (b == 0)
            printf("Eixo X\n");
        else if (a == 0)
            printf("Eixo Y\n");
        else if (a > 0 && b > 0)
            printf("Q1\n");
        else if (a  <  0 && b > 0)
            printf("Q2\n");
        else if (a < 0 && b < 0)
            printf("Q3\n");
        else 
            printf("Q4\n");
        }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4.5 -2.2

Output

x
+
cmd
Q4

#2 Code Example with C++ Programming

Code - C++ Programming



#include <cstdio>
int main() {
    float x;
    float x;

    scanf ("%f", &x);
    scanf ("%f", &y);
        
        if (x == 0 && y == 0) {
            printf("Origem\n");
        } else if (x == 0) {
            printf("Eixo Y\n");
        } else if (y == 0) {
            printf("Eixo X\n");
        } else if (x > 0 && y > 0) {
            printf("Q1\n");
        } else if (x > 0 && y  <  0) {
            printf("Q4\n");
        } else if (x < 0 && y > 0) {
            printf("Q2\n");
        } else {
            printf("Q3\n");
        }
       
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
0.1 0.1

Output

x
+
cmd
Q1

#3 Code Example with Java Programming

Code - Java Programming



import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        
        float x;
        float y;
        Scanner sc = new Scanner(System.in);

        x = sc.nextFloat();
        y = sc.nextFloat();
        
        average =((N1 * 2)+(N2 + 3)+(N3 * 4)+(N4 * 1))/10;

        if (x == 0 && y == 0) {
            System.out.printf("Origem\n");
        } else if (x == 0) {
            System.out.printf("Eixo Y\n");
        } else if (y == 0) {
            System.out.printf("Eixo X\n");
        } else if (x > 0 && y > 0) {
            System.out.printf("Q1\n");
        } else if (x > 0 && y  <  0) {
            System.out.printf("Q4\n");
        } else if (x < 0 && y > 0) {
            System.out.printf("Q2\n");
        } else {
            System.out.printf("Q3\n");
        }
       
    return 0;
       
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
0.0 0.0

Output

x
+
cmd
Origem

#4 Code Example with Python Programming

Code - Python Programming



X,Y=list(map(float,input().split()))
if(X==0 and Y==0):
    print("Origem")
elif(X==0):
    print("Eixo Y")
elif(Y==0):
    print("Eixo X")
elif(X>0 and Y>0):
    print("Q1")
elif(X<0 and Y>0):
    print("Q2")
elif(X<0 and Y < 0):
    print("Q3">
elif(X>0 and Y<0):
    print("Q4">
Copy The Code & Try With Live Editor

Input

x
+
cmd
4.5 -2.2

Output

x
+
cmd
Q4
Advertisements

Demonstration


Previous
#1040 Beecrowd Online Judge Solution 1040 Average 3- Solution in C, C++, Java, Python and C#
Next
#1042 Beecrowd Online Judge Solution 1042 Simple Sort Solution in C, C++, Java, Python and C#