zoukankan      html  css  js  c++  java
  • ACM——线性表操作

    线性表操作

    时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte
    总提交:2795            测试通过:589

    描述

     

    线性表是n个元素的有序集合(n³0),n是线性表中元素的个数,称为线性表的长度。可以用一组地址连续的存储单元依次存储线性表中元素,采用这种存储方式的线性表称为顺序表。

    请在顺序表上实现运算,实现顺序表的逆置,删除表中所有元素值等于x的元素。

    输入

     

    三组数据,顺序表元素类型分别为整型、字符型和实型。

    每一组第一行给出元素数目n0<n1000),第二行给出元素数值,第三行给出待删除的元素。

    输出

     

    三组数据,每一组第一行为逆置后的顺序表元素,第二行是在此基础上删除指定元素后的顺序表元素

    样例输入

    8
    1 2 3 7 5 6 7 8 
    7
    3
    a c m
    h
    4
    1.2 3.4 5.6 7.8
    1.2

    样例输出

    8 7 6 5 7 3 2 1 
    8 6 5 3 2 1 
    m c a 
    m c a 
    7.8 5.6 3.4 1.2 
    7.8 5.6 3.4 

    提示

     

    该题属于南京邮电大学《数据结构A》实验一中的内容,验证的是课本代码,每一个输出元素后均有一个空格(包括最后一个元素),请慎重解答。

    题目来源

    CHENZ

     

    #include<iostream>
    using namespace std;
    template<class T>
    class SeqList
    {
    private:
        T * elements;
        int maxLength;
        int n;
    public:
        SeqList(int nSize)
        {
            maxLength=nSize;
            elements=new T[maxLength];
            n=0;
        }
        void Insert(T x)
        {
            if(n>=maxLength)
                cout<<"out of bounds"<<endl;
            elements[n]=x;
            n++;
        }
        void Delete(T x)
        {
            for(int i=0;i<n;i++)
            {
                if(elements[i]==x)
                {
                    for(int j=i;j<n;j++)
                        elements[j]=elements[j+1];
                    n--;
                    i--;
                }
            }
        }
        void outPut()
        {
            for(int i=n-1;i>=0;i--)
            {
                cout<<elements[i]<<" ";
            }
            cout<<endl;
        }
    };
    int main()
    {
        int n;
        cin>>n;
        SeqList<int> list(n);
        int x;
        for(int i=0;i<n;i++)
        {
            cin>>x;
            list.Insert(x);
        }
        cin>>x;
    
        int size;
        cin>>size;
        SeqList<char> clist(size);
        char ch;
        for(int k=0;k<size;k++)
        {
    
            cin>>ch;
            clist.Insert(ch);
        }
        cin>>ch;
    
        int size2;
        cin>>size2;
        SeqList<float> flist(size2);
        float value;
        for(int m=0;m<size2;m++)
        {
            cin>>value;
            flist.Insert(value);
        }
        cin>>value;
    
        list.outPut();
        list.Delete(x);
        list.outPut();
        clist.outPut();
        clist.Delete(ch);
        clist.outPut();
        flist.outPut();
        flist.Delete(value);
        flist.outPut();
        return 0;
    }

     

    题目链接http://202.119.236.66:9080/acmhome/problemdetail.do?&method=showdetail&id=1004

     

  • 相关阅读:
    Java 8 Lambda 表达式
    OSGi 系列(十二)之 Http Service
    OSGi 系列(十三)之 Configuration Admin Service
    OSGi 系列(十四)之 Event Admin Service
    OSGi 系列(十六)之 JDBC Service
    OSGi 系列(十)之 Blueprint
    OSGi 系列(七)之服务的监听、跟踪、声明等
    OSGi 系列(六)之服务的使用
    OSGi 系列(三)之 bundle 事件监听
    OSGi 系列(三)之 bundle 详解
  • 原文地址:https://www.cnblogs.com/BasilLee/p/3784695.html
Copyright © 2011-2022 走看看