ACM-linear table operations

Source: Internet
Author: User

Linear table operation time limit (Common/Java): 1000 MS/3000 MS running memory limit: 65536 KByte
Total submissions: 2795 pass the test: 589

Description

 

A linear table is an ordered set of n elements (n ³ 0). n is the number of elements in a linear table. It is called the length of a linear table. You can store elements in a linear table in sequence using a set of sequential storage units. Linear tables that use this storage method are called sequential tables.

Perform operations on the sequence table to reverse the sequence table and delete all elements with an element value equal to x in the table.

 

Input

 

There are three groups of data. The sequence table element types are integer, complex, and real.

The first row of each group is given the number of elements n (0 <n ≤ 1000), the second row is given the element value, and the third row is given the element to be deleted.

 

Output

 

Three groups of data, each group of first-row reverse sequence table elements, and the second row is to delete the sequence table elements after the specified elements.

 

Sample Input

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

Sample output

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

Prompt

 

This is part of the content in the "data structure A" experiment of Nanjing University of Posts and Telecommunications. It verifies the textbook code. Each output element has A space (including the last element). Please answer it carefully.

 

Question Source

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

 

Link: http: // 202.119.236.66: 9080/acmhome/problemdetail. do? & Method = showdetail & id = 1004

 

 

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.