Advertisement
Guest User

Untitled

a guest
Mar 15th, 2022
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int A[] = { -5,1,-6,2,-7,3 };
  9.     int n = sizeof( A ) / sizeof( int );
  10.     std::vector< int > B;
  11.    
  12.     int* pIter = &A[ 0 ];
  13.     int* pLast = &A[ n-1 ];
  14.    
  15.     int nMax = 0, nCur = 0;
  16.     while( pIter != pLast )
  17.     {
  18.         pIter++;
  19.         nCur++;
  20.         if( *pIter > A[ nMax ] ) nMax = nCur;
  21.        
  22.     }
  23.    
  24.     pLast = &A[nMax];
  25.     pIter = &A[0];
  26.    
  27.     while( pIter != pLast )
  28.     {
  29.         if( *pIter < 0 ) B.push_back( *pIter );
  30.         pIter++;
  31.     }
  32.    
  33.     for( auto& i : B )
  34.     {
  35.         cout << i << endl;
  36.     }
  37.  
  38.     return 0;
  39. }#include <iostream>
  40. #include <vector>
  41.  
  42. using namespace std;
  43.  
  44. int main()
  45. {
  46.     int A[] = { -5,1,-6,2,-7,3 };
  47.     int n = sizeof( A ) / sizeof( int );
  48.     std::vector< int > B;
  49.    
  50.     int* pIter = &A[ 0 ];
  51.     int* pLast = &A[ n-1 ];
  52.    
  53.     int nMax = 0, nCur = 0;
  54.     while( pIter != pLast )
  55.     {
  56.         pIter++;
  57.         nCur++;
  58.         if( *pIter > A[ nMax ] ) nMax = nCur;
  59.        
  60.     }
  61.    
  62.     pLast = &A[nMax];
  63.     pIter = &A[0];
  64.    
  65.     while( pIter != pLast )
  66.     {
  67.         if( *pIter < 0 ) B.push_back( *pIter );
  68.         pIter++;
  69.     }
  70.    
  71.     for( auto& i : B )
  72.     {
  73.         cout << i << endl;
  74.     }
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement