Page 4 of 4

### Re: Help me with 496

Posted: Mon Feb 18, 2013 5:51 am
Please, help me I am getting WA... I have no idea... Why I am getting this?

Code: Select all

``````#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <map>
#include <iterator>
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
map<long,long> AA, BB;
long a=0,b=0, n, nl=0, m=0;
char ch;
//freopen("in-496.txt","r",stdin);
//freopen("496.txt","W",stdout);
while(scanf("%ld",&n) && scanf("%c",&ch)==1)
{
if(( (int)ch==32 || (int)ch==10) && nl==0)
{
AA[n]=n;
a++;
}
if(( (int)ch==32 || (int)ch==10) && nl==1)
{
if(AA[n]==n){
m++;
}
BB[n]=n;
b++;
}
if((int)ch==10 || ch=='\0')
{
nl++;
}

if(nl==2)
{
if(a==b)
{
if(m==a){
printf("A equals B\n");
}
else if(m>0){
printf("I'm confused!\n");
}
else{
printf("A and B are disjoint\n");
}
}
else if(a>b)
{
if(m==b){
printf("B is a proper subset of A\n");
}
else{
printf("I'm confused!\n");
}
}
else
{
if(m==a){
printf("A is a proper subset of B\n");
}
else{
printf("I'm confused!\n");
}
}

nl=0;
a=0; b=0;
AA.clear(); BB.clear();
m=0;
}
}
return 0;
}

``````

### Re: Help me with 496

Posted: Tue Feb 19, 2013 10:29 pm
Doesn't match the sample I/O.

### Re: Help me with 496

Posted: Sun Jun 15, 2014 1:09 am
I am getting WA...
Need Some Critical Case

Code: Select all

``````
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<iterator>
#include<cassert>
#include <sstream>
using namespace std;

/*------- Constants---- */
#define MX 1030
#define ll long long
#define ull unsigned long long
#define mod 1000000007

/* -------Global Variables ------ */
ll x,y,d;

/*---- short Cuts ------- */
#define ms(ara_name,value) memset(ara_name,value,sizeof(ara_name))

/*------ template functions ------ */
template < class T > inline T gcd(T a , T b ) { if(b==0) return a; else return gcd(b, a%b);}
template < class T > inline T lcm(T a , T b ) { return  a*b / gcd(a, b);}
template < class T > inline T extended_euclid_returning_gcd(T a,T b){ T t; if(b==0){d = a;x=1;y=0;} else {extended_euclid_returning_gcd(b, a%b); t=x; x=y;y = t-(a*y/b);}}
template < class T > inline T absolute(T a ) { if(a>0) return a; else return -a;}
template < class T > inline T reverse_num( T a ){ T x=0,tmp = a; while(tmp) { x=10*x+ tmp % 10; tmp/=10;} return x;}
template <class T > inline T big_mod(T base, T power){ T res=1; while (power) { if(power&1){ res*=base; power--;} base =base *base; power/=2;} return res;}

string str1,str2,tmp;
vector<int>ara1,ara2;
set<int> setA,setB;
int main()
{
set<int>:: iterator it;
int num,i,disJoint,equal,a_subset_B,b_subset_A,confisued,flag,j;
while (getline(cin,str1)) {
getline(cin,str2);
istringstream iss(str1);
while (iss>>tmp) {

num= atoi(tmp.c_str());
setA.insert(num);
}
istringstream iss2(str2);
while (iss2>>tmp) {
num= atoi(tmp.c_str());
setB.insert(num);
}
disJoint=equal=a_subset_B=b_subset_A=confisued=1;
for (it=setA.begin(); it!=setA.end(); it++) {
ara1.push_back(*it);
}
for (it=setB.begin(); it!=setB.end(); it++) {
ara2.push_back(*it);
}
sort(ara1.begin(), ara1.end());
sort(ara2.begin(), ara2.end());

if(ara2.size()==ara1.size()){
a_subset_B=0;
b_subset_A=0;
for (i=0; i<ara1.size(); i++) {
if(ara1[i]!=ara2[i]) break;
}
if(ara1.size()!=i) equal=0;

for (i=0; i<ara1.size(); i++) {
flag=0;
for (j=0; j<ara2.size(); j++) {
if(ara1[i]==ara2[j]){
disJoint=0;
flag=1;
break;
}
}
}
}
else {
equal=0;
if(ara1.size()>ara2.size()){
a_subset_B=0;
for (i=0; i<ara2.size(); i++) {
flag=0;
for (j=0; j<ara1.size(); j++) {
if(ara1[i]==ara2[j]){
flag=1;
break;
}
}
if(flag) {
disJoint=0;
}
else {
b_subset_A=0;
}
}

}
if(ara2.size()>ara1.size()){
b_subset_A=0;
for (i=0; i<ara1.size(); i++) {
flag=0;
for (j=0; j<ara2.size(); j++) {
if(ara2[i]==ara1[j]){
flag=1;
break;
}
}
if(flag) {
disJoint=0;
}
else {
a_subset_B=0;
}
}

}
}

if (equal) printf("A equals B");
else if (a_subset_B) printf("A is a proper subset of B");
else if (b_subset_A) printf("B is a proper subset of A");
else if( disJoint) printf("A and B are disjoint");
else if (confisued) printf("I'm confused!");
printf("\n");

ara2.clear();
ara1.clear();
setA.clear();
setB.clear();
}

return 0;
}
``````

### Re: Help me with 496

Posted: Mon Jun 16, 2014 8:55 pm

Code: Select all

``````set_intersection(setA.begin(), setA.end(), setB.begin(), setB.end(), insert_iterator<set<int> > (inter, inter.begin()));
if(setA == setB)
printf("A equals B\n");
else if(setA == inter)
printf("A is a proper subset of B\n");
else if(setB == inter)
printf("B is a proper subset of A\n");
else if(inter.size() == 0)
printf("A and B are disjoint\n");
else
printf("I'm confused!\n");
``````