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)