Friday, June 3, 2016

URI Online Judge Solution 1115 || Quadrant

URI Online Judge | 1115

Quadrant

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
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 SampleOutput Sample
2 2
3 -2
-8 -1
-7 1
0 2
primeiro
quarto
terceiro
segundo


URI Online Judge Solution  1115 || Quadrant in C

#include <stdio.h>

int main()
{
    int x;
    int y;

    scanf("%d", &x);
    scanf("%d", &y);

    if(x == 0 || y == 0){
            return 0;
    }

    while(x != 0 || y != 0){

        if(x > 0 && y > 0){
            printf("primeiro\n");
        }
        if(x < 0 && y > 0){
            printf("segundo\n");
        }
        if(x < 0 && y < 0){
            printf("terceiro\n");
        }
        if(x > 0 && y < 0){
            printf("quarto\n");
        }

        scanf("%d", &x);
        scanf("%d", &y);

        if(x == 0 || y == 0){
            return 0;
        }
    }

    return 0;
}




URI Online Judge Solution  1115 || Quadrant in JAVA

import java.io.IOException;
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
        int firstsign, secondSign;
        Scanner input = new Scanner(System.in);
        while (((firstsign = input.nextInt()) != 0)
                && ((secondSign = input.nextInt()) != 0)) {
            if (firstsign > 0 && secondSign > 0) {
                System.out.print("primeiro\n");
            } else if (firstsign > 0 && secondSign < 0) {
                System.out.print("quarto\n");
            } else if (firstsign < 0 && secondSign < 0) {
                System.out.print("terceiro\n");
            } else if (firstsign < 0 && secondSign > 0) {
                System.out.print("segundo\n");
            }
        }
    }
}



Dropbox download link
URI Question link

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.