Răspuns :
#include <iostream>
#include <fstream>
using namespace std;
//t=1 inseamna ca sunt aceleasi
int main()
{
int v[50],a[50],i,k,j,q,aux,n,t=1;
cout<<"n=";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<"a["<<i<<"]=";
cin>>a[i];
}
for(j=1;j<=n;j++)
{
cout<<"v["<<j<<"]=";
cin>>v[j];
}
for(i=1;i<n;i++)
for(k=i+1;k<=n;k++)
if(a[i]>a[k])
{
aux=a[i];
a[i]=a[k];
a[k]=aux;
}
for(j=1;j<n;j++)
for(q=j+1;q<=n;q++)
if(v[j]>v[q])
{
aux=v[j];
v[j]=v[q];
v[q]=aux;
}
cout<<endl;
cout<<"a[i]: ";
for(i=1;i<=n;i++)
cout<<a[i]<<" ";
cout<<endl;
cout<<"v[j]: ";
for(j=1;j<=n;j++)
cout<<v[j]<<" ";
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(v[i]!=v[j])
t=0;
if(t==0)
cout<<"Da";
else
cout<<"Nu";
}
Sper să te ajute!
COROANA TE ROG!!!
METODA 1 - FARA SORTARE SI EFICIENT
#include<iostream>
using namespace std;
int main(){
int v1[101], v2[101], n, sem;
cin>>n;
for(int i=1;i<=n;i++)
cin>>v1[i];
for(int i=1;i<=n;i++){
cin>>v2[i];
sem=0;
for(int j=1;j<=n;j++)
if(v2[i]==v1[j])
sem=1;
if(sem==0){
cout<<"Nu";
return 0;
}
}
cout<<"Da";
return 0;
}
METODA 2 - CU SORTARE SI SEMI-EFICIENTA
#include<iostream>
using namespace std;
int main(){
int v1[101], v2[101], n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>v1[i];
for(int i=1;i<=n;i++)
cin>>v2[i];
for(int i=1;i<=n-1;i++)
for(int j=i+1;j<=n;j++){
if(v1[i]>v1[j])
swap(v1[i],v1[j]);
if(v2[i]>v2[j])
swap(v2[i],v2[j]);
}
for(int i=1;i<=n;i++)
if(v1[i]!=v2[i]){
cout<<"Nu";
return 0;
}
cout<<"Da";
return 0;
}
METODA 3 - CU SORTARE SI EFICIENTA!!!
#include<iostream>
using namespace std;
int main(){
int v1[101], v2[101], n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>v1[i];
int x=v1[i];
int p=i-1;
while(p>=0&&v1[p]>x){
v1[p+1]=v1[p];
p--;
}
v1[p+1]=x;
}
for(int i=1;i<=n;i++){
cin>>v2[i];
int x=v2[i];
int p=i-1;
while(p>=0&&v2[p]>x){
v2[p+1]=v1[p];
p--;
}
v1[p+1]=x;
}
for(int i=1;i<=n;i++)
if(v1[i]!=v2[i]){
cout<<"Nu";
return 0;
}
cout<<"Da";
}