fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, count = 0;
  6. cin >> n;
  7. int arr[n];
  8. for (int i = 0; i < n; i++){
  9. cin >> arr[i];
  10. if (arr[i] < 0){
  11. count++;
  12. }
  13. }
  14. if(count == 0){
  15. cout << "NO";
  16. } else {
  17. cout << count << endl;
  18. for (int c = n - 1; c >= 0; c--){
  19. if (arr[c] < 0){
  20. cout << arr[c] << " ";
  21. }
  22. }
  23. }
  24. return 0;
  25. }
Success #stdin #stdout 0s 4360KB
stdin
7
-2 5 4 -3 7 -1 0
stdout
3
-1 -3 -2