034:goodcopy

 

 1 #include <iostream>
 2 using namespace std;
 3 
 4 
 5 template <class T>
 6 struct GoodCopy {
 7 // 在此处补充你的代码
 8     void operator()(T* p,T* q,T* r){
 9         int n = q - p;
10         while(n + 1){
11             *(r + n) = *q;
12             -- n;
13             -- q;
14         }
15     }
16 };
17 
18 int a[200];
19 int b[200];
20 string c[200];
21 string d[200];
22 
23 template <class T>
24 void Print(T s,T e) {
25     for(; s != e; ++s)
26         cout << * s << ",";
27     cout << endl;
28 }
29 
30 int main()
31 {
32     int t;
33     cin >> t;
34     while( t -- ) {
35         int m ;
36         cin >> m;
37         for(int i = 0;i < m; ++i)
38             cin >> a[i];
39         GoodCopy<int>()(a,a+m,b);//这里创建了一个临时对象
40         Print(b,b+m);
41         GoodCopy<int>()(a,a+m,a+m/2);
42         Print(a+m/2,a+m/2 + m);
43 
44         for(int i = 0;i < m; ++i)
45             cin >> c[i];
46         GoodCopy<string>()(c,c+m,d);
47         Print(c,c+m);
48         GoodCopy<string>()(c,c+m,c+m/2);
49         Print(c+m/2,c+m/2 + m);
50     }
51     return 0;
52 }

 

posted @ 2022-09-10 17:17  balabalahhh  阅读(35)  评论(0)    收藏  举报