zoukankan      html  css  js  c++  java
  • Problem X: 删除数组元素

    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

    10
    1 2 3 4 5 1 2 3 4 5
    1
    

      

    Sample Output

    1 2 3 4 5 1 2 3 4 5
    2 3 4 5 2 3 4 5
    

      

    HINT

     

    Append Code

    #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;
    }
    

      

    作者:7oDo

    仅供参考,请勿抄袭。

    Hang Hang Hang !!!

  • 相关阅读:
    快速排序?
    算法和数据结构?
    渲染一个react?
    移动端兼容适配?
    PWA全称Progressive Web App,即渐进式WEB应用?
    InnoDB一棵B+树可以存放多少行数据?
    移动端首屏优化?
    InnoDB什么时候会锁表?
    数组去重,多种方法?
    如何处理异形屏iphone X?
  • 原文地址:https://www.cnblogs.com/Jie-Fei/p/9153748.html
Copyright © 2011-2022 走看看