Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdlib>
  4. #include <time.h>
  5.  
  6. using namespace std;
  7.  
  8. void print_array(vector<vector<int> > arg){
  9.     for(int i = 0; i < arg.size(); i++){
  10.         for(int j = 0; j < arg[i].size(); j++){
  11.             cout << ' '<< arg[i][j];
  12.         }
  13.         cout << endl;
  14.     }
  15. }
  16.  
  17. void print_array(vector<int> arg){
  18.     for(int i = 0; i < arg.size(); i++){
  19.         cout << ' ' << arg[i];
  20.     }
  21.     cout << endl;
  22. }
  23.  
  24. vector<int> rand_arr(){
  25.     int tmp = 0;
  26.     vector<int> output;
  27.     int arr_size = rand() % 5 + 1;
  28.     for(int i = 0; i <= arr_size; i++){
  29.         tmp = rand() % 5 -2;
  30.         output.push_back(tmp);
  31.     }
  32.     return output;
  33. }
  34.  
  35. int main(){
  36.     int rows = 0;
  37.     vector<vector<int> > source;
  38.     vector<int> positive;
  39.     vector<int> negative;
  40.    
  41.     srand(time(NULL));
  42.     rows = rand() % 5 + 1;
  43.     for(int i = 0; i < rows; i++){
  44.         source.push_back(rand_arr());
  45.     }
  46.     cout << "initial array:\n";
  47.     print_array(source);
  48.     for(int i = 0; i < source.size(); i++){
  49.         for(int j = 0; j < source[i].size(); j++){
  50.             if(source[i][j] > 0){
  51.                 positive.push_back(source[i][j]);
  52.             }
  53.             if(source[i][j] < 0){
  54.                 negative.push_back(source[i][j]);
  55.             }
  56.         }
  57.     }
  58.     cout << "positive numbers: \n";
  59.     print_array(positive);
  60.     cout << "negative numbers: \n";
  61.     print_array(negative);
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement