Please Login in order to post a comment
#include <iostream> #include <set> using namespace std; int main() { int q; cin >> q; set<int> set; while (q > 0) { int y, x; cin >> y >> x; switch (y) { case 1: { set.insert(x); break; } case 2: { set.erase(x); break; } default: if (set.end() != set.find(x)) cout << "Yes" << endl; else cout << "No" << endl; break; } q--; } }
int main() { set s; int q; int a; int y; cin>>q; while(q>0){ cin>>a; if(a==1){ cin>>y;
s.insert(y); } else if(a==2){ cin>>y; auto it=s.find(y); if(it!=s.end()){ s.erase(*it); } else{ continue; } } else if(a==3){ cin>>y; auto itr=s.find(y); if(itr!=s.end()){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } } q--; } return 0;
}
Here is Sets-STL problem solution in C++ - https://programmingoneonone.com/hackerrank-sets-stl-solution-in-cpp.html
//M.Kohaku
using namespace std;
int main(){ sets; int n; cin >> n; for(int i=0;i p; cin >> p.first >> p.second; int x = p.first; int y = p.second; if(x==1){ s.insert(y); } else if(x==2){ s.erase(y); } else if(x==3){ if(s.count(y)) cout << "Yes" << endl; else cout << "No" << endl; } } }
My solution:
int main() { set<int> values; int queries, qType, qVal; cin >> queries; while(queries) { cin >> qType >> qVal; switch (qType) { case 1: values.insert(qVal); break; case 2: values.erase(qVal); break; case 3: if(values.find(qVal) != values.end()) cout << "Yes\n"; else cout << "No\n"; break; } queries--; } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
int main() { set s; int q; int a; int y; cin>>q; while(q>0){ cin>>a; if(a==1){ cin>>y;
}
Here is Sets-STL problem solution in C++ - https://programmingoneonone.com/hackerrank-sets-stl-solution-in-cpp.html
//M.Kohaku
include
using namespace std;
int main(){ sets; int n; cin >> n; for(int i=0;i p; cin >> p.first >> p.second; int x = p.first; int y = p.second; if(x==1){ s.insert(y); } else if(x==2){ s.erase(y); } else if(x==3){ if(s.count(y)) cout << "Yes" << endl; else cout << "No" << endl; } } }
My solution: