Problem X: Delete array element time limit:1 Sec Memory limit:128 MB
submit:375 solved:151
[Submit] [Status] [Web Board] Description
Defines the array class, where there is only one array of type int and the number of array elements is unknown.
Overloads its <<, >>,-operators. where "<<" outputs all the array elements, separated by 1 spaces between 22, ">>" reads the array elements according to the input format; "-" receives a parameter of type int and deletes an element with an equal to a in the array.
Input
The input has 3 rows. The first line n>0; the second row is n integers, the array element, and the 3rd line is an int type number, which is the number that needs to be removed from the array.
Output
See examples.
Sample Input
101 2 3 4 5 1 2 3 4 51
Sample Output
1 2 3 4 5 1 2 3 4 52 3 4 5 2 3 4 5
HINT Append codeappend.cc,
#include <iostream> #include <list>using namespace Std;class Array{public:list<int> num; Friend IStream &operator>> (IStream &is, Array &p) {int n; is>>n; for (int i=0; i<n; i++) {int temp; is>>temp; P.num.push_back (temp); } return is; } friend Ostream &operator<< (ostream &os, Array &p) {list<int>::iterator pp; For (Pp=p.num.begin (); Pp!=p.num.end (); pp++) {if (Pp==p.num.begin ()) os<<*pp; else os<< "" <<*pp; } os<<endl; return OS; } Array &operator-(int a) {num.remove (a); return *this; }};int Main () {int A; Array arr; cin>>arr; cout<<arr; cin>>a; arr = arr-a; cout<<arr; return 0;}
Problem X: Delete array elements