Problem X: 刪除數組元素

來源:互聯網
上載者:User

標籤:friend   iter   remove   geo   sub   input   stream   operator   opera   

Problem X: 刪除數組元素Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 375  Solved: 151
[Submit][Status][Web Board]
Description

定義Array類,其中只有一個int類型的數組,數組元素個數未知。

重載其<<、>>、-運算子。其中"<<"輸出所有的數組元素,兩兩之間用1個空格隔開;">>"根據輸入的格式讀取數組元素;"-"接收一個int類型的參數a,將數組中與a相等的元素刪除。

Input

輸入有3行。第一行N>0;第二行是N個整數,是數組元素;第3行是一個int類型數,是需要從數組中刪除的數。

Output

見範例。

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: 刪除數組元素

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.