Advertisement
paramecium

Zaba

May 19th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdlib>
  4. #include <iomanip>
  5. #include <vector>
  6. #include <queue>
  7. #include <cstring>
  8. #include <string>
  9. #include <fstream>
  10. #include <deque>
  11. #include <algorithm>
  12.  
  13. using namespace std;
  14.  
  15.  
  16.  
  17. void show(int *arr, int size){
  18.     for(int i = 0; i <  size; i++)
  19.         cout << arr[i] << " ";
  20.     cout << endl;
  21. }
  22.  
  23. int min(int a, int b){
  24.     return (a < b) ? a : b;
  25. }
  26.  
  27. int *resize(int *arr, int *old_size, int new_size){
  28.     int *new_arr = new int[new_size],i;
  29.     for ( i = 0; i < min(*old_size, new_size); i++)
  30.         new_arr[i] = arr[i];
  31.     for ( i; i < new_size; i++)
  32.         new_arr[i] = 0;
  33.     delete [] arr;
  34.    *old_size = new_size;
  35.     return new_arr;
  36. }
  37.  
  38.   int main()
  39.   {
  40.     int n=0,sum=0;
  41.     cin>>n;
  42.     int *mas= new int [n];
  43.     for(int i=0;i<n;i++){
  44.         cin>>mas[i];
  45.     }
  46.     int i=0;
  47.     while(i<n-1){
  48.         if(mas[i]>=mas[i+1]){
  49.           for(int j=i+1;j<n-1;j++){
  50.             mas[j]=mas[j+1];
  51.           }
  52.           mas=resize(mas,&n,n-1);
  53.         }
  54.         else{
  55.             i++;
  56.         }
  57.  
  58.     }
  59.     for( i=0;i<n;i++){
  60.         cout<<mas[i]<<" ";
  61.     }
  62.     delete  [] mas;
  63.  
  64.     return 0;
  65.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement