Saturday, April 30, 2016

URI Solution 1041 in C C++ and Java language || Coordinates of a Point



URI Online Judge | 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 over 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 over X axis write "Eixo X", else if the point is over 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 SampleOutput Sample
4.5 -2.2Q4
0.1 0.1Q1
0.0 0.0Origem

URI 1041 Solution in Java language

import java.util.Scanner;
public class URI_1041 {
public static void main(String[] args) {
float X, Y;
Scanner input =new Scanner(System.in);
X = input.nextFloat();
Y = input.nextFloat();
if (X == 0.0 && Y == 0.0) {
System.out.print("Origem\n");
}else if (X == 0.0 && Y != 0.0) {
System.out.print("Eixo Y\n");
}else if (Y == 0.0 && X != 0.0) {
System.out.print("Eixo X\n");
}else if (X > 0.0 && Y > 0.0) {
System.out.print("Q1\n");
}else if (X < 0.0 && Y < 0.0) {
System.out.print("Q3\n");
}else if (X < 0.0 && Y > 0.0) {
System.out.print("Q2\n");
}else  {
System.out.print("Q4\n");
}
}
}

URI 1041 Solution in C language

#include<stdio.h>

int main() {
float X, Y;
scanf("%f%f", &X,&Y);
if (X == 0.0 && Y == 0.0) {
printf("Origem\n");
}else if (X == 0.0 && Y != 0.0) {
printf("Eixo Y\n");
}else if (Y == 0.0 && X != 0.0) {
printf("Eixo X\n");
}else if (X > 0.0 && Y > 0.0) {
printf("Q1\n");
}else if (X < 0.0 && Y < 0.0) {
printf("Q3\n");
}else if (X < 0.0 && Y > 0.0) {
printf("Q2\n");
}else  {
printf("Q4\n");
}

return 0;
}



No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.