#include <iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
int main() {
int i,sum,sum1,n;
cin>>n;
vector<int>pre;
set<int>s1;
set<int>s2;
int temp1[n];
int temp2[n];
for(i=0;i<n;++i)
cin>>temp1[i];
for(i=0;i<n;++i)
cin>>temp2[i];
for(i=0;i<sizeof(temp1);++i)
s1.insert(temp1[i]);
for(i=0;i<sizeof(temp2);++i)
s1.insert(temp2[i]);
for(i=n;i>=0;--i)
sum+=i;
for(i=0;i<s1.size();++i)
sum1+=s1[i];
if(sum==sum1)
cout<<"I become the guy.";
else
cout<<"Oh, my keyboard!";
return 0;
}
ideone link:https://ideone.com/trfOz0 i am trying to add the elements in the set s1 but it seems like this way is not working,how can i do it?
You can't index a
std::set
. It's not built that way. You can check for membership, but you can't just pick then
th element.In order to take the sum, you'd have to iterate over the set - but not via index, via iterators:
Or using
std::accumulate
:Or in C++11: