fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7. bool present[n+1];
  8. for (int i = 0; i <= n; i++) {
  9. present[i] = false;
  10. }
  11.  
  12. for (int i = 0; i < n; i++) {
  13. int x;
  14. cin >> x;
  15. if (x <= n && x > 0) {
  16. present[x] = true;
  17. }
  18. }
  19.  
  20. for (int i = 1; i <= n; i++) {
  21. if (!present[i]) {
  22. cout << i;
  23. break;
  24. }
  25. }
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0.01s 5312KB
stdin
7
1 7 5 4 2 3
stdout
6