Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
---|---|---|---|---|---|---|
| discuss496 - | Accepted | C++11 | 0.000 | 0.000 | 1444 | 47 secs ago |
Suggest: O(nlogn)
- Not need math just only SET data struct
- Compare length of vector (a, b) and set (ab) to get result
#include<bits/stdc++.h>
#define int long long
using namespace std;
string s;
vector<int> f(){
s+=" ";
string x="";
vector<int> a;
for(int i=0; s[i]; i++){
if (s[i]==' '){
a.push_back(stoll(x));
x="";
}
else x+=s[i];
}
return a;
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
while(getline(cin, s)){
vector<int> a, b;
a= f();
getline(cin, s);
b= f();
set<int> ab;
for(auto x:a) ab.insert(x);
for(auto x:b) ab.insert(x);
int la=a.size(), lb= b.size(), lab= ab.size();
if (la == lab && lb == lab) cout<<"A equals B";
else
if (la == lab && lb < lab) cout<<"B is a proper subset of A";
else
if (lb == lab && la < lab) cout<<"A is a proper subset of B";
else
if (lb + la == lab) cout<<"A and B are disjoint";
else
if (lb + la > lab) cout<<"I'm confused!";
cout<<"\n";
}
}
No comments:
Post a Comment