I love reading the most!
2000 pages of book!
What page should I read next???
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
The input consists of multiple sets of data. Each set starts with a number N (0 ≤ N ≤ 1000), representing the number of pages you've previously read (which might be repeated). Following that are N positive integers ranging from 1 to 2000, indicating the pages you've read. | A number indicates the next page you should read, which is the first page in the book that you haven't read yet. |
5 1 3 4 5 6 4 1 2 3 4 5 2 3 4 5 6 | 2 5 1 |
Thought Process
Since the problem specifies that N won't exceed 1000 and the maximum number of pages is 2000, you can use a for loop from 1 to 2000 to check which pages you haven't read yet. Output the current page number you've reached and then break the loop. You can use a map to keep track of which pages you've read and use a for loop to determine which pages haven't been read to find the answer.
Sample Code-ZeroJudge A282: Study Hard
#include <iostream>
#include <map>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(nullptr);
int N;
while (cin >> N)
{
map<int, int>MAP;
for (int i = 0; i<N; i++)
{
int tmp;
cin >> tmp;
MAP[tmp] = 1;
}
for (int i = 1; i<=2000; i++)
{
if (MAP[i] == 0)
{
cout << i << endl;
break;
}
}
}
}
//ZeroJudge A282
//Dr. SeanXD