-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBitsetBillionInts.cpp
executable file
·55 lines (50 loc) · 1.08 KB
/
BitsetBillionInts.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <fstream>
#include <string>
#include <bitset>
using namespace std;
int main()
{
ifstream iFile("billionInts.txt");
string line;
bitset<1000> myNumBitSet;
if (iFile.is_open())
{
// VERY IMP
while (getline(iFile, line))
{
if (!iFile.eof())
{
int x = stoi(line);
myNumBitSet[x] = 1;
}
else
{
cout << "EOF reached" << endl;
}
}
/*
while (!iFile.eof())
{
getline(iFile, line);
cout << line << endl;
//int x = stoi(line);
//myNumBitSet[x] = 1;
}
*/
iFile.close();
}
else
{
cout << "Error opening the file" << endl;
}
// Go through the bits and find the one that is not set.
for (size_t i = 0; i < myNumBitSet.size(); ++i)
{
if (myNumBitSet[i] == 0)
{
// This is the missing number
cout << "Missing Num: " << i << endl;
}
}
}