RECTANGL - Editorial

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

I thought so, but I guess I was fooled by the weak cases thanks to bring this to my notice and also I try not to use memory for trivial problems as such, but honestly sorting was the first thing came to my mind also.:smile:

1 Like

You aren’t saving any memory here I think. You have 4 variables declared. You will have exactly 4 declared variables in any case.

#include <stdio.h>

int main(void) {

int t,a,b,c,d;
scanf("%d",&t);
if(t>=1&&t<=1000)
{
while(t--)
{
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a>=1&&b>=1&&c>=1&&d>=1&&a<=10000&&b<=10000&&c<=10000&&d<=10000)
    {
    if(a==b&&c==d)
    {
        printf("Yes\n");
    }
    else if(a==c&&b==d)
    {
        printf("Yes\n");
    }
    else if(a==d&&b==c)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    }
}
}
return 0;

}

what’s wrong in my code