Algorithm
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1115
Quadrant
Adapted by Neilor Tonin, URI Brazil
Write a program to read the coordinates (X, Y) of an indeterminate number of points in Cartesian system. For each point write the quadrant to which it belongs. The program finish when at least one of two coordinates is NULL (in this situation without writing any message).
Input
The input contains several tests cases. Each test case contains two integer numbers.
Output
For each test case, print the corresponding quadrant which these coordinates belong, as in the example.
Input Sample | Output Sample |
2 2 |
primeiro |
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
int main(){
while(1){
int x, y;
cin >> x >> y;
if (x == 0 || y == 0){
break;
}
else if (x > 0 && y > 0){
cout << "primeiro" << endl;
}
else if (x > 0 && y < 0){
cout << "quarto" << endl;
}
else if (x < 0 && y < 0){
cout << "terceiro" << endl;
}
else{
cout << "segundo" << endl;
}
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with Java Programming
Code -
Java Programming
import java.io.IOException;
import java.util.Scanner;
public class Main{
public static void main(String[] args) throws IOException{
Scanner input = new Scanner(System.in);
while(true){
int x = input.nextInt();
int y = input.nextInt();
if (x == 0 || y == 0){
break;
}
else if (x > 0 && y > 0){
System.out.println("primeiro");
}
else if (x > 0 && y < 0){
System.out.println("quarto");
}
else if (x < 0 && y < 0){
System.out.println("terceiro");
}
else{
System.out.println("segundo");
}
}
}
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Javascript Programming
Code -
Javascript Programming
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
// var lines = input.split('\n');
var sep = [' ', '\n'];
// console.log(separators.join('|'));
var line = input.split(new RegExp(sep.join('|'), 'g'));
while(true){
var x = parseInt(line.shift());
var y = parseInt(line.shift());
if (x === 0 || y === 0){
break;
}
else if (x > 0 && y > 0){
console.log("primeiro");
}
else if (x > 0 && y < 0){
console.log("quarto");
}
else if (x < 0 && y < 0){
console.log("terceiro");
}
else{
console.log("segundo");
}
}
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Python Programming
Code -
Python Programming
while(True):
x, y = map(int, input().split(" "))
if (x == 0 or y == 0):
break
elif (x > 0 and y > 0):
print("primeiro")
elif (x > 0 and y < 0):
print("quarto")
elif (x < 0 and y < 0):
print("terceiro")
else:
print("segundo")
Copy The Code &
Try With Live Editor
Input
Output