Răspuns :
A)
#include <iostream>
#include <algorithm>
using namespace std;
int A[10000], B[10000];
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i++)
cin >> A[i];
sort(&A[1], &A[n+1]);
int i;
for(i = 1; i <= n && A[i] < 0; i++);
reverse(&A[i], &A[n+1]);
for(i = 1; i <= n; i++)
B[i] = A[i];
for(i = 1; i <= n; i++)
cout << B[i] << " ";
}
B)
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
struct marfa{
string denumire;
double pret;
int an;
int cantitate;
};
bool cmp_denumire(marfa a, marfa b){
return a.denumire < b.denumire;
}
bool cmp_pret(marfa a, marfa b){
return a.pret < b.pret;
}
bool cmp_an(marfa a, marfa b){
return a.an < b.an;
}
marfa vec[10000];
int main(){
int n;
cin >> n;
for(int i = 0; i < n; i++){
cout << "Denumire:"; cin >> vec[i].denumire;
cout << "Pret:"; cin >> vec[i].pret;
cout << "Anul fabricarii:"; cin >> vec[i].an;
cout << "Cantitate:"; cin >> vec[i].cantitate;
}
sort(&vec[0], &vec[n], cmp_denumire);
cout << "Sortat dupa denumire:\n";
for(int i = 0; i < n; i++){
cout << vec[i].denumire << " " << vec[i].pret << " " << vec[i].an << " " << vec[i].cantitate<<"\n";
}
sort(&vec[0], &vec[n], cmp_pret);
cout << "Sortat dupa pret:\n";
for(int i = 0; i < n; i++){
cout << vec[i].denumire << " " << vec[i].pret << " " << vec[i].an << " " << vec[i].cantitate<<"\n";
}
sort(&vec[0], &vec[n], cmp_an);
cout << "Sortat dupa an:\n";
for(int i = 0; i < n; i++){
cout << vec[i].denumire << " " << vec[i].pret << " " << vec[i].an << " " << vec[i].cantitate<<"\n";
}
}