Posted: Mon Jan 26, 2004 2:46 pm
I have AC on this problem and if you want I can help you:
give me some inputs and I will give you right outputs.
give me some inputs and I will give you right outputs.
1 2 3
1 3 3 - A equals B
This answer is wrong. This answer will be- B is a proper subset of A.
No set will contain the same integer twice...Each line of text (set) will be a list of distinct integers.
are you sure??Mahmud776 wrote:Hello eXon:
I checked your inputs with my accepted program and did not find any mistake.
But, May be, there is no such input that contain blank lines. Because, I got accepted without considering this.
1 2 3
1 3 3 - A equals B
This answer is wrong. This answer will be- B is a proper subset of A.
Code: Select all
#include<stdio.h>
#include<set>
#include<stdlib.h>
using namespace std;
void main(){
int sizea,sizeb,common;
set<int> A,B;
char seta[2000],setb[2000],*p;
bool asubset,bsubset,disjoint,equal;
while(gets(seta)!=NULL){
gets(setb);
A.clear();B.clear();
asubset=bsubset=disjoint=equal=false;
common=0;
p=strtok(seta," ");
A.insert(atoi(p));
while((p=strtok(NULL," "))!=NULL) A.insert(atoi(p));
p=strtok(setb," ");
B.insert(atoi(p));
while((p=strtok(NULL," "))!=NULL) B.insert(atoi(p));
sizea=A.size();sizeb=B.size();
set<int> ::iterator pa,pb;
if(sizea==sizeb){
for(pa=A.begin();pa!=A.end();pa++) if(B.find(*pa)!=B.end()) common++;
if(common==sizea){equal=true;disjoint=asubset=bsubset=false;}
else if(!common){equal=asubset=bsubset=false;disjoint=true;}
}
else if(sizea<sizeb){
for(pa=A.begin();pa!=A.end();pa++) if(B.find(*pa)!=B.end()) common++;
if(common==sizea && common==sizeb-1) {asubset=true;bsubset=disjoint=equal=false;}
else if(!common) {disjoint=true;asubset=bsubset=equal=false;}
}
else {
for(pb=B.begin();pb!=B.end();pb++) if(A.find(*pb)!=A.end()) common++;
if(common==sizeb && common==sizea-1) {bsubset=true;asubset=disjoint=equal=false;}
else if(!common) {disjoint=true;asubset=bsubset=equal=false;}
}
if(asubset && !bsubset && !equal && !disjoint) puts("A is a proper subset of B");
else if(!asubset && bsubset && !equal && !disjoint) puts("B is a proper subset of A");
else if(!asubset && !bsubset && equal && !disjoint) puts("A equals B");
else if(!asubset && !bsubset && !equal && disjoint) puts("A and B are disjoint");
else if(!asubset && !bsubset && !equal && !disjoint) puts("I'm confused!");
}
}
Code: Select all
#include<iostream>
#include<set>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
class anupam
{
private:
set<long int> A;
public:
string z;
void initialize()
{
A.clear();
char* b;
char a[z.length()];
for(int i=0;i<z.length();i++)
a[i]=(char)z[i];
b=strtok(a," ");
A.insert(atoi(b));
while((b=strtok(NULL," "))!= NULL)
A.insert(atoi(b));
}
void check(anupam nn)
{
int m=0,n=0;
set<long int>:: iterator anu,pat;
for((anu=(nn.A).begin());anu!=((nn.A).end());anu++)
{
if(A.find(*anu)!=A.end())
n++;
}
for(anu=A.begin();anu!=A.end();anu++)
{
if((nn.A).find(*anu)!=(nn.A).end())
m++;
}
if((n==m)&&(A.size()==((nn.A).size()))&&(A.size()==n))
{
cout<<"A equals B"<<endl;
return;
}
if(((n==A.size())&&(m!=(nn.A).size()))||((int)((char)z[0])==0))
{
cout<<"A is a proper subset of B"<<endl;
return;
}
if(((n!=A.size())&&(m==(nn.A).size()))||((int)((char)(nn.z[0]))==0))
{
cout<<"B is a proper subset of A"<<endl;
return;
}
if((n==0)&&(m==0))
{
cout<<"A and B are disjoint"<<endl;
return;
}
if((n!=A.size())&&(m!=(nn.A).size()))
{
cout<<"I'm confused!"<<endl;
return;
}
}
};
int main()
{
anupam a,n;
string x;
while(getline(cin,x,'\n'))
{
a.z=x;
getline(cin,x,'\n');
n.z=x;
char f=a.z[0];
char g=n.z[0];
if(((int)f==0)&&((int)g==0))
{
cout<<"A equals B"<<endl;
continue;
}
a.initialize();
n.initialize();
a.check(n);
}
return 0;
}
Code: Select all
for input
-9 -9
9 -9
your output is...
A and B are disjoint
this should be
A is a proper subset of B
A set contains unique elements. It cannot have (by definition) -9 listed twice. So I guess this case can't be tested.vinit_iiita wrote: for input
-9 -9
9 -9