RECTANGL - Editorial

PROBLEM LINK:

Practice
Contest

Author: Hasan Jaddouh
Tester: Alexey Zayakin
Editorialist: Oleksandr Kulkov

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Common sense

PROBLEM:

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:

int a[4];
cin >> a[0] >> a[1] >> a[2] >> a[3];
sort(a, a + 4);
cout << (a[0] == a[1] && a[2] == a[3] ? "YES" : "NO") << "\n";

AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.
Tester’s solution can be found here.

RELATED PROBLEMS:

2 Likes

#include<stdio.h>

void main()
{
int a,b,c,d,e;
clrscr();
printf(“enter the no of test cases”);
scanf("%d",&a);
printf(“entrt the values of sides”);
scanf("%d%d%%d%d");
if(a==b&&c==d)
{
if(b==c)
printf(“no”);
else
printf(“yes”);
}
else if(b==c&&a==d)
{
if(a==c)
printf(“no”);
else
printf(“yes”);
else
printf(“no”);
getch();
}

@harsha_5

  1. Dont use void main. Its not allowed anymore I believe. Use int main().
  2. If you are serious about competitive programming, consider switching to c++. Its much more powerful.
  3. 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.
  4. It can be a square. Nowhere in the problem was written otherwise.
  5. There are several beginner’s guide you can find by some googling. Read them
2 Likes

Exactly same solution i did…

your Editorials are not visible below the questions we need to find editorial in discussion part. kindly add a link below question its self

#include
using namespace std;
int main()
{
int a,b,c,d,t;
int n=0;
cin>>t;
for(int i=1;i<=t;i++)
{
cin>>a>>b>>c>>d;
if(a==b)
n++;

		if(a==c)
		n++;
	
		if(a==d)
		n++;
	
		if(b==c)
		n++;
		
		if(b==d)
		n++;
	
		if(c==d)
		n++;
		
	{	if(n==2)
				cout<<"YES\n";
		else
			cout<<"NO\n";
	}
		n=0;		
}
return 0;
} 

//what’s wrong with my code. I haven’t used sort function.

What if its a square? Square is a rectangle with length=breadth.

1 Like

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t–)
{
int a,count=0;
unordered_map<int,int> m;
for(int i=0;i<4;i++)
{
cin>>a;
m[a]++;
}
for(auto i:m)
{
if(i.second==2)
count++;
}
if(count==2)
cout<<“YES”;
else
cout<<“NO”;
cout<<"\n";

}

}
what is wrong with this code?please look once

you are forgetting that square is also a rectangle.

ha… thank you shivamchef i found that i missed squares case after posting this and i didnot find a way to delete it .sorry for this silly doubt

welcome and it’s not a silly one.

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

what is the problem with this code??

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 :sweat_smile:

1 Like

Beat me to posting a counter-example :slight_smile:

(mine would have been

1
3 6 1 4

)

1 Like

I hope this will Help You alot :
Just Go Through this

And Subscribe my channel Hello World Please.

hey guys i got a doubt in this question

if you provide 1,1,1,1 as output it is giving “YES” but it should be “NO” bcoz it becomes a square.

Squares are a special case of Rectangles.

Square is a special case of rectangle as we just want the opposite sides to be equal.

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;
}

1 Like

This is wrong, though, and only gets AC due to weak testcases; see here for a counter-example.

@admin/ @melfice - can we get some stronger testcases added? e.g.

1
1 3 5 7

(courtesy of @ankurparihar) and

1
3 6 1 4
1 Like