fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin>>n;
  7. int *x = new int [n];
  8. for ( int i=0; i<n; i++ ) {
  9. cin>>x[i];
  10. }
  11. int num=0;
  12. for ( int i=0; i<n; i++ ) {
  13. if (x[i]>0 ) {
  14. num++ ;
  15. }
  16. }
  17. if (num == 0) {
  18. cout<<"NO";
  19. }
  20. if ( num != 0 ) {
  21. cout<<num;
  22. }
  23. cout<<endl;
  24. for ( int i=0; i<n; i++ ) {
  25. cin>>x[i];
  26. }
  27. for ( int i=0; i<n; i++ ) {
  28. if ( x[i]>0 ) {
  29. cout<<x[i]<<" ";
  30. }
  31. }
  32. }
  33.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
NO