1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 template <class T> 5 class Array{ 6 private: 7 T *p; 8 int length; 9 public: 10 Array(int l) 11 { 12 p=new T[l+1]; 13 length=l; 14 } 15 void put(int n) 16 { 17 int i; 18 for (int k=0;k<length-1;k++) 19 for (int j=k+1;j<length;j++) 20 if (p[k]<p[j]) 21 swap(p[k],p[j]); 22 23 if (n>=length) 24 { 25 for (i=0;i<length-1;i++) 26 cout<<p[i]<<" "; 27 cout<<p[i]<<endl; 28 } 29 else 30 { 31 for (i=0;i<n-1;i++) 32 cout<<p[i]<<" "; 33 cout<<p[i]<<endl; 34 } 35 } 36 int size() 37 { 38 return length; 39 } 40 T& operator[](int n) 41 { 42 return p[n]; 43 } 44 friend istream& operator >> (istream &is,Array &c) 45 { 46 T b; 47 is >> b; 48 return is; 49 } 50 ~Array() 51 { 52 delete[]p; 53 } 54 }; 55 56 int main() 57 { 58 int cases, len; 59 cin >> cases; 60 for(int ca = 1; ca <= cases; ca++) 61 { 62 cin >> len; 63 if(ca % 3 == 0) 64 { 65 Array<char> chr_arr(len); 66 for(int i = 0; i < chr_arr.size(); i++) 67 cin >> chr_arr[i]; 68 chr_arr.put(10); 69 } 70 if(ca % 3 == 1) 71 { 72 Array<int> int_arr(len); 73 for(int i = 0; i < int_arr.size(); i++) 74 cin >> int_arr[i]; 75 int_arr.put(10); 76 } 77 if(ca % 3 == 2) 78 { 79 Array<double> dbl_arr(len); 80 for(int i = 0; i < dbl_arr.size(); i++) 81 cin >> dbl_arr[i]; 82 dbl_arr.put(10); 83 } 84 } 85 }