Kosty_Fomin

Untitled

Jul 4th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 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.     bool per = false;
  9.     std::srand(std::time(0));
  10.    
  11.     std::cout<<"Input N:";
  12.     std::cin>>n;
  13.    
  14.     std::cout<<"If you want random generation - input 1\n If you want hand-made generation - input 0\n";
  15.     std::cin>>ch;
  16.     long* mas = new long[n];
  17.    
  18.     for(int i = 0; i<n; i++){
  19.         switch (ch) {
  20.             case 0:
  21.                 std::cin>>mas[i];
  22.                 break;
  23.             case 1:
  24.                 mas[i] = rand();
  25.                 break;
  26.             default:
  27.                 break;
  28.         }
  29.        
  30.     }
  31.    
  32.    
  33.    
  34.     for (int i = 0; i<n; i++) {
  35.         std::cout<<mas[i]<<" ";
  36.     }
  37.     std::cout<<"\n";
  38.    
  39.     for (int i = 0; i < n; i++) {
  40.         for (int j = 0; j < n-i-1; j++) {
  41.           if (mas[j] > mas[j+1]) {
  42.               long b = mas[j];
  43.                mas[j] = mas[j+1];
  44.                mas[j+1] = b;
  45.                per = true;
  46.             }
  47.         }
  48.        
  49.         if(per==false){
  50.             break;
  51.         }
  52.     }
  53.    
  54.     for (int i = 0; i<n; i++) {
  55.         std::cout<<mas[i]<<" ";
  56.     }
  57.    
  58.     delete[] mas;
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment