Solution of 11455 - Behold my quadrangle

Problem Description
source: https://uva.onlinejudge.org/external/114/11455.html

Any square is a rectangle, any rectangle is a quadrangle, and any quadrangle is composed of four sides. But not all rectangles are squares, not all quadrangles are rectangles, and not all sets of four sides are quadrangles. We have the length of four sides. You have to determine if they can form a square. If not, determine if they can form a rectangle. If not, determine if they can form a quadrangle. 

Input 

The first line of the input contains an integer indicating the number of test cases. For each test case, there is a line with four positive integer numbers, between 0 and 230

Output 

For each test case, the output should consist of a line with the text ‘square’, ‘rectangle’, ‘quadrangle’ or ‘banana’, if the sides of the corresponding case can form a square, a rectangle, a quadrangle or none, respectively. 

Sample Input 


10 8 7 6 
9 1 9 1 
29 29 29 29 
5 12 30 7

Sample Output 

quadrangle 
rectangle 
square 
banana


Solution:
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include<stdio.h>
#include<stdlib.h>

using namespace std;
int main()
{
    long long int a,b,c,d,t,i;
    while(scanf("%lld",&t)==1)
    {
        for(i=1;i<=t;i++)
        {
            scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
            if(a==b && b==c && c==d)
                printf("square\n");
            else if((a==b && c==d)||(a==c && b==d)||(a==d && b==c))
                printf("rectangle\n");
            else if((a<=(b+c+d))&&(b<=(a+c+d))&&(c<=(a+b+d))&&(d<=(a+b+c)))
                printf("quadrangle\n");
            else
                printf("banana\n");

        }
    }
    return 0;
}
image

No comments:

Post a Comment

Write your comment - Share Knowledge and Experience