a very simple problem

This commit is contained in:
Mhrooz 2023-11-29 10:07:39 +01:00
parent d332a8b675
commit 5b5f172e6b

36
2336-231129-pass/main.cpp Normal file
View File

@ -0,0 +1,36 @@
#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;
}