Advertisement
Loloped

Удаление в массиве с k до p

Feb 20th, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5. int main()
  6. {
  7.     int n; cout<<"n="; cin>>n;
  8.     int *a=new int [n];
  9.     for (int i=0; i<n; i++)
  10.     {
  11.         cout<<"a["<<i<<"]="; cin>>a[i];
  12.     }
  13.     int k; cout<<"k="; cin >>k;
  14.     int p; cout<<"p="; cin >>p;
  15.     int e;
  16.     if (k>p) {e=k; k=p; p=e;}
  17.     e=p-k;
  18.     if (k<0 || k>n-1 || p<0 || p>n-1)
  19.         cout <<"error";
  20.     else {for (int i=k; i<n-1; i++) a[i]=a[i+e+1];
  21.     n--;
  22.     for (int i=0; i<n; i++) cout << a[i]<<"\t";}
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement