Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
SPOJ Problem: OLOLO
1. Level up your coding skills with
the C++ Standard Template
Library (STL):
SPOJ Problem: OLOLO
BY JOYJIT CHOUDHURY
2. OLOLO - Onotole needs your help
Is accessible at - http://www.spoj.com/problems/OLOLO/
3. Problem Statement
Onotole has a lot of pyani. Each pyani has a
number, writing on it.
Pyanis with equal numbers are indistinguishable.
Onotole knows everything, so, he knows that each
pyani appeared twice, and only one pyani is
unique. He wants to get вздръжни эффект, and he
needs the unique pyani.
Given the list of pyanis denote which one of them
appeared once (it is guaranteed that
other pyanis appeared twice).
4. Input
First line of input contains number of pyanis
N <= 500 000. Next N lines contain a single positive
integer 1 <= Pi <= 10^9.
Output
Output one positive integer on pyani, which appeared
once.
Time limit: 0.134s
Source limit: 50000B
Memory limit: 1536MB
5. So, the idea is…
There will be N numbers as input
All the numbers come in pairs, except one of them
We have to output that one number
6. So…
There can be many different approaches to solving this problem
(read: using XOR)
A solution using std::unordered_set will be demonstrated here
For every number Pi, we check whether it’s already in the set
or not:
If it’s not present, that means it’s the first occurrence of the
number. Thus, we insert it into the set
If it is present, that means it has occurred once before. So, we
remove it from the set
7. In the End
There will be just one number left in the
unordered_set
The one which didn’t come in pair
The one we need to output