玛贝拉 2017-03-05 07:50 采纳率: 0%
浏览 3248

PTA数组模板题目求解答,小白,白的彻底

对于输入的每一批数,按从小到大排序后输出。
一行输入为一批数,第一个输入为数据类型(1表示整数,2表示字符型数,3表示有一位小数的浮点数,4表示字符串,0表示输入结束),第二个输入为该批数的数量size(0 输出将从小到大顺序输出数据。
函数接口定义:sort函数将接受size个数据,将它们从小到大排序后存在a指向的一段连续空间中。template void sort(T a, int size);裁判测试程序样例:
#include #include using namespace std;
/
请在这里填写答案 /
template
void display(T
a, int size){
for(int i=0; i cout cout }
int main() {
const int SIZE=10;
int a[SIZE];
char b[SIZE];
double c[SIZE];
string d[SIZE];
int ty, size;
cin>>ty;
while(ty>0){
cin>>size;
switch(ty){
case 1:sort(a,size);
display(a,size); break;
case 2:sort(b,size);
display(b,size); break;
case 3:sort(c,size);
display(c,size); break;
case 4:sort(d,size);
display(d,size); break;
}
cin>>ty;
}
return 0;
}
输入样例:1 3 3 2 12 2 a A3 3 1.5 2.6 2.24 2 bca abc0
输出样例:1 2 3A a1.5 2.2 2.6abc bca

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-03-05 10:49
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题