Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdlib>
- #include <iomanip>
- #include <vector>
- #include <queue>
- #include <cstring>
- #include <string>
- #include <fstream>
- #include <deque>
- #include <algorithm>
- using namespace std;
- void show(int *arr, int size){
- for(int i = 0; i < size; i++)
- cout << arr[i] << " ";
- cout << endl;
- }
- int min(int a, int b){
- return (a < b) ? a : b;
- }
- int *resize(int *arr, int *old_size, int new_size){
- int *new_arr = new int[new_size],i;
- for ( i = 0; i < min(*old_size, new_size); i++)
- new_arr[i] = arr[i];
- for ( i; i < new_size; i++)
- new_arr[i] = 0;
- delete [] arr;
- *old_size = new_size;
- return new_arr;
- }
- int main()
- {
- int n=0,sum=0;
- cin>>n;
- int *mas= new int [n];
- for(int i=0;i<n;i++){
- cin>>mas[i];
- }
- int i=0;
- while(i<n-1){
- if(mas[i]>=mas[i+1]){
- for(int j=i+1;j<n-1;j++){
- mas[j]=mas[j+1];
- }
- mas=resize(mas,&n,n-1);
- }
- else{
- i++;
- }
- }
- for( i=0;i<n;i++){
- cout<<mas[i]<<" ";
- }
- delete [] mas;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement