Problem A: Array Class (I)

Source: Internet
Author: User
Tags int size

Problem A: Array class (I) time limit:1 Sec Memory limit:128 MB
submit:3295 solved:2418
[Submit] [Status] [Web Board] The description encapsulates an integer array class for storing integer and processing related functions, and supports the following operations: 1. Array::array () Non-parametric construction method: Creates an empty array object. 2. Array::size () Method: Returns the number of elements in an Array object. 3. Array::get (int N) method: reads the n element from the input in the format. 4. Subscript operator: Returns the element to which the subscript refers. -----------------------------------------------------------------------------you design an array class to make the main () function work correctly. The function call format is shown in append.cc. The main () function is given in append.cc

The first integer n of input inputs, indicating that there are n sets of test data. Each subsequent line begins with an integer k, indicating that there is a K integer followed.

Output outputs an array of inputs. Each row of data corresponds to one output. The format is shown in Sample.

Sample Input
42 10 201 003 1 2 3

  

Sample Output
10 2001 2 3

  

HINT Append codeappend.cc,
int main () {    int cases;    Array arr;    cin >> cases;    for (int CA = 1; CA <= cases; ca++)    {        int len;        Cin >> Len;        Arr.get (len);        for (int i = 0; i < arr.size (); i++)            if (i + 1 = = Arr.size ())                cout << arr[i];            else                cout << arr[i] << "";        cout << Endl;    }}

  

#include <iostream> #include <vector>using namespace Std;class array{public:    vector<int> num;    int Len;    Array (): Len (0) {}    int size ()    {        return len;    }    void get (int n)    {        len=n;        Num.resize (len);        for (int i=0; i<n; i++)        {            int t; cin>>t;            num[i]=t;            Num.push_back (t); Reset, can not continue to add the tail of the vector, otherwise it is increasing the length of the vector.        }    }    int operator[] (int n)    {        return num[n];}    }; int main () {    int cases;    Array arr;    cin >> cases;    for (int CA = 1; CA <= cases; ca++)    {        int len;        Cin >> Len;        Arr.get (len);        for (int i = 0; i < arr.size (); i++)            if (i + 1 = = Arr.size ())                cout << arr[i];            else                cout << arr[i] << "";        cout << Endl;    }}

  

Problem A: Array Class (I)

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.