Jump to content

Hello everyone,

 

I began solving problems on HackerRank and I can't figure out the one with the lonely integer. The problem statement is: "There are N integers in an array A. All but one integer occur in pairs. Your task is to find out the number that occurs only once." Below is the code they provide and they ask from me to figure out what the lonelyinteger function should do. I have trouble completing the task because I've never worked with vectors before and I don't have a clue of how to implement the xor operator.

 

Any help would be greatly appreciated! :)

#include <map>#include <set>#include <list>#include <cmath>#include <ctime>#include <deque>#include <queue>#include <stack>#include <bitset>#include <cstdio>#include <limits>#include <vector>#include <cstdlib>#include <numeric>#include <sstream>#include <iostream>#include <algorithm>using namespace std;int lonelyinteger(vector < int > a) {return 0;}int main() {    int res;        int _a_size;    cin >> _a_size;    cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');     vector<int> _a;    int _a_item;    for(int _a_i=0; _a_i<_a_size; _a_i++) {        cin >> _a_item;        _a.push_back(_a_item);    }        res = lonelyinteger(_a);    cout << res;        return 0;}
Link to comment
https://linustechtips.com/topic/307995-need-help-c/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×