【思路】:三种方法1. malloc。2. new。3.vector声明的时候定义。如下:
【AC代码】:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
//freopen("in.txt", "r", stdin);
int len = 0, sum = 0, i = 0;
cin >> len;
int *p = new int[len];
//1. p = (int*)malloc(len*sizeof(int));
//2. int *p = new int[len]; 需delete []p;
//3. vector<int> a(len)
for (i = 0; i < len; i++)
{
cin >> p[i];
sum += p[i];
}
cout << sum << " " << sum/len;
}