Problem X: Delete array elements

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.