#include <iostream>
using namespace std;
int main()
{
int t, i = 0, j = 0;
cin >> t;
char *pc = nullptr;//初始化
int *pi = nullptr;//初始化
float *pf = nullptr;//初始化
int sum=0;
int FLAG = 0;
while (FLAG < t)
{
char ch;
cin >> ch;
int n;
i = 0, j = 0;
if (ch == 'I')
{
cin >> n;
sum = 0;
pi = new int[n]; // 动态分配内存
for (i = 0; i < n; i++)
{
cin >> *(pi + i);
sum += *(pi + i);
}
cout << sum / n << endl;
delete[] pi; // 释放内存
pi = nullptr; // 设置为 nullptr
}
else if (ch == 'C')
{
cin >> n;
char *chArray = new char[n]; // 动态分配内存
char max = chArray[0];
pc = chArray;
for (int z = 0; z < n; z++)
{
cin >> *(pc + z);
}
for (int Z = 0; Z < n; Z++)
{
if (*(pc + Z) > max)
{
max = *(pc + Z);
}
}
cout << max << endl;
delete[] chArray; // 释放内存
pc = nullptr; // 设置为 nullptr
}
else if (ch == 'F')
{
cin >> n;
pf = new float[n]; // 动态分配内存
for (int j = 0; j < n; j++)
{
cin >> *(pf + j);
}
float min = *(pf + 0);
for (int I = 0; I < n; I++)
{
if (*(pf + I) < min)
{
min = *(pf + I);
}
}
cout << min << endl;
delete[] pf; // 释放内存
pf = nullptr; // 设置为 nullptr
}
FLAG++;
}
return 0;
}
【1】动态内存-->待更......