You’re given four numbers a, b, c, d. You have to determine if you can make a rectangle of such lengthes.
QUICK EXPLANATION
Do what the problem asks you to do.
EXPLANATION:
In other words you have to check if two smallest and two largest numbers among this four are same. To do this you can sort all four numbers in whatever way you like and check that first two and last two numbers are both same. Example of solution:
Dont use void main. Its not allowed anymore I believe. Use int main().
If you are serious about competitive programming, consider switching to c++. Its much more powerful.
You dont have to print things like “enter the values” etc. Read output specifications of a problem carefully. Only print according to the given format. Like “yes” and “no” had to be uppercase.
It can be a square. Nowhere in the problem was written otherwise.
There are several beginner’s guide you can find by some googling. Read them
try:
n=int(input())
list1=[]
while(n>0):
flag=0
list2=list(map(int,input().split()))
for i in list2:
if(list2.count(i)==2 or list2.count(i)==4):
flag=1
else:
flag=0
if(flag==1):
list1.append(‘YES’)
else:
list1.append(‘NO’)
n-=1
for i in list1:
print(i)
except:
pass
You can also use xor operator.
If a xor b xor c xor d == 0 then it is a rectangle, otherwise not.
xor of two same numbers is zero, and positive for any two different numbers.
My code:
#include <iostream>
using namespace std;
int main(){
int t, a, b, c, d;
cin >> t;
while(t-->0){
cin >> a >> b >> c >> d;
if((a^b^c^d)==0) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
Although this is not true always, as for example
1, 3, 5, 7 also gives zero upon xor
You don’t have to use memory, you don’t have to sort things, our beloved XOR is the best. #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double old; #define mod 1000000007 #define pub(a) push_back(a) #define mp(a,b) make_pair(a,b)
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t–){
ll a,b,c,d;
cin>>a>>b>>c>>d;
if((a^b^c^d)==0){
cout<<“YES”<<’\n’;
}else{
cout<<“NO”<<’\n’;
}
}
return 0;
}