Description
Input
Output
Sample Input
Sample Output
HINT
Append Code
#include<iostream>
using namespace std;
template<class T>
class Array
{
private:
T *sss;
int si;
public:
Array(int l):si(l){sss=new T[si];}
~Array(){if (sss!=NULL)delete []sss;}
int size(){return si;}
void put(int n)
{
int i,j;
for(i=0;i<si-1;i++)//挨着和每个比,最后一个不用了
{
for(j=i+1;j<si;j++)//从下一个开始,到最后
{
if(sss[i]<sss[j])
{
T t=sss[i];
sss[i]=sss[j];
sss[j]=t;
}
}
}
if(n>si)
n=si;
cout<<sss[0];
for(int i=1;i<n;i++)
cout<<" "<<sss[i];
cout<<endl;
}
T& operator[](int n)//少个引用,我去
{
return sss[n];
}
};
int main()
{
int cases, len;
cin >> cases;
for(int ca = 1; ca <= cases; ca++)
{
cin >> len;
if(ca % 3 == 0)
{
Array<char> chr_arr(len);
for(int i = 0; i < chr_arr.size(); i++)
cin >> chr_arr[i];
chr_arr.put(10);
}
if(ca % 3 == 1)
{
Array<int> int_arr(len);
for(int i = 0; i < int_arr.size(); i++)
cin >> int_arr[i];
int_arr.put(10);
}
if(ca % 3 == 2)
{
Array<double> dbl_arr(len);
for(int i = 0; i < dbl_arr.size(); i++)
cin >> dbl_arr[i];
dbl_arr.put(10);
}
}
}