Kosty_Fomin

Untitled

Jul 4th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. //XCODE
  2.  
  3. #include <iostream>
  4.  
  5. int main(int argc, const char * argv[]) {
  6.     long n,k,buf;
  7.     bool ch;
  8.     std::srand(std::time(0));
  9.    
  10.     std::cout<<"Input N:";
  11.     std::cin>>n;
  12.    
  13.     std::cout<<"If you want random generation - input 1\n If you want hand-made generation - input 0\n";
  14.     std::cin>>ch;
  15.     long* mas = new long[n];
  16.    
  17.     for(int i = 0; i<n; i++){
  18.         switch (ch) {
  19.             case 0:
  20.                 std::cin>>mas[i];
  21.                 break;
  22.             case 1:
  23.                 mas[i] = rand();
  24.                 break;
  25.             default:
  26.                 break;
  27.         }
  28.        
  29.     }
  30.    
  31.    
  32.    
  33.     for (int i = 0; i<n; i++) {
  34.         std::cout<<mas[i]<<" ";
  35.     }
  36.     std::cout<<"\n";
  37.    
  38.     for (int i = 0; i<n; i++) {
  39.         if (mas[i]==0) {
  40.             for (int j = i+1; j<n; j++) {
  41.                 buf = mas[j];
  42.                 mas[j] = mas[j-1];
  43.                 mas[j-1] = buf;
  44.             }
  45.         }
  46.     }
  47.    
  48.    
  49.     for (int i = 0; i<n; i++) {
  50.         std::cout<<mas[i]<<" ";
  51.     }
  52.    
  53.     delete[] mas;
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment