-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0005.cpp
63 lines (53 loc) · 1.16 KB
/
0005.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <string>
using namespace std;
// 在此处补充你的代码
template<typename T1,int size>
class A{
public:
// A<T1,size>()
T1* arr;
A<T1,size>(T1 ptr_arr[]){
arr = new T1 [size];
for(int i = 0;i < size;++i)
arr[i] = ptr_arr[i];
}
void operator=(T1 ptr_arr[]){
if(arr != nullptr)
delete [] arr;
arr = new T1 [size];
for(int i = 0;i < size;++i)
arr[i] = ptr_arr[i];
}
T1 operator[](const int& i){
return arr[i];
}
T1 sum(void){
T1 ans = arr[0];
for(int i = 1;i < size;++i)
ans += arr[i];
return ans;
}
};
int main() {
int t;
cin >> t;
while( t -- ) {
int b1[10];
for(int i = 0;i < 10; ++i)
cin >> b1[i];
A<int, 10> a1 = b1;
cout << a1[2] << endl;
double b2[5] ;
for(int i = 0;i < 5; ++i)
cin >> b2[i];
A<double, 5> a2 = b2;
cout << a2.sum() << endl;
string b3[4] ;
for(int i = 0;i < 4; ++i)
cin >> b3[i];
A<string, 4> a3 = b3;
cout << a3.sum() << endl;
}
return 0;
}