fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main(void)
  7. {
  8. int N;
  9. cin >> N;
  10.  
  11. int * A = new int [N];
  12.  
  13. for (int i = 0; i < N; i++)
  14. cin >> A[i];
  15.  
  16. sort(A, A + N);
  17. int answer = 1;
  18. for (int i = 0; i < N; i++)
  19. {
  20. if (answer != A[i]) break; //다르다면 중지
  21. for (int j = i + 1; j < N; j++) //중복된 값 무시
  22. {
  23. if (A[i] == A[j]) i = j;
  24. else break;
  25. }
  26. answer++;
  27. }
  28. cout << answer;
  29. delete[] A;
  30. }
Success #stdin #stdout 0s 5612KB
stdin
5
4 1 2 7 8
stdout
3