#include
#include
#include<math.h>
#include
using namespace std;
class Solution {
public:
vectorsortedSquares(vector& A)
{
int tmp = 0;
int len = A.size();
for (int i = 0;i < len;i++)
{
A[i] = pow(A[i], 2);
}
sort(A.begin(), A.end());//完全为了节省时间和内存
return A;
}
};
int main()
{
int n = 0;
cout << "please Enter the lenth of the array: ";
cin >> n;
vectorarr(n);
cout << "please input the element of the array: “;
for (int& a : arr)
{
cin >> a;
}
Solution s;
s.sortedSquares(arr);
for (int a : arr)
{
cout << a<<” ";
}
return 0;
}