36 lines
725 B
C++
36 lines
725 B
C++
|
#include<bits/stdc++.h>
|
||
|
using namespace std;
|
||
|
|
||
|
class SmallestInfiniteSet {
|
||
|
public:
|
||
|
const int length = 1010;
|
||
|
bool nums[1010];
|
||
|
SmallestInfiniteSet() {
|
||
|
for(int i = 0 ; i <length ;i++) nums[i] = 1;
|
||
|
}
|
||
|
|
||
|
int popSmallest() {
|
||
|
int i = 1;
|
||
|
while(nums[i]==0) i++;
|
||
|
nums[i] = 0;
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
void addBack(int num) {
|
||
|
nums[num] = 1;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
int main(){
|
||
|
SmallestInfiniteSet sol;
|
||
|
|
||
|
sol.addBack(2);
|
||
|
cout<<sol.popSmallest()<<endl;;
|
||
|
cout<<sol.popSmallest()<<endl;;
|
||
|
cout<<sol.popSmallest()<<endl;;
|
||
|
sol.addBack(1);
|
||
|
cout<<sol.popSmallest()<<endl;;
|
||
|
cout<<sol.popSmallest()<<endl;;
|
||
|
cout<<sol.popSmallest()<<endl;;
|
||
|
return 0;
|
||
|
}
|