Written by Zeyneb_Semedli
In this problem we are asked to check whether it is possible to create a parallelogram with the given numbers.
First, 4 numbers are given in the input: a b c and d. If we look at the properties of the parallelogram, we will see that its opposite sides are equal to each other:
b
-------
a / / c
-------
dif so, then a=b,c=d.
To solve the problem, let's collect the given numbers in an array.
int n=4;
double a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}Let's not forget that the numbers given in the input are of "double" type :)
The second step is to stack the array from smallest to largest.That is to sort.
sort(a,a+n)Let's not forget that we need a new library to implement the sorting function. The name of the library is:
#include <cmath>And after that, we need to consider the property of the parallelogram in our code.since our numbers are already sorted, we just need to check the equality of the first 2 and last 2 numbers of the array.
After checking the elements of the array, "YES" if it matches our property:
if(a[0]==a[1] && a[2]==a[3])
{
cout<<"YES";
}otherwise:
else
{
cout<<"NO";
}Let's take a look at our code in general:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n=4;
double a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
if(a[0]==a[1] && a[2]==a[3])
{
cout<<"YES";
}
else
{
cout<<"NO";
}
}