Răspuns :
#include <iostream>
using namespace std;
void citire(int a[], int &n)
{
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
}
void afisare(int a[], int n)
{
for(int i=1;i<=n;i++) cout<<a[i]<<" ";
cout<<endl;
}
int asemenea(int a, int b)//verifica cara a si b sunt asemenea
{
int fa[10]={0}, fb[10]={0};//doi vectori caracteristici pt cifrele fiecarui numar
while(a>0)
{
fa[a%10]=1; a=a/10;
}
while(b>0)
{
fb[b%10]=1; b=b/10;
}
for(int c=0;c<=9;c++)// pt fiecare cifra
if(fa[c]!=fb[c]) return 0; // 0 si 1 sau 1 si 0
return 1;
}
int stergij(int a[], int &n, int x,int y)//sterge din a elementele cu indicii intre x si y
{
for(int i=1;i<=y-x+1;i++)
for(int j=x;j<n;j++)
a[j]=a[j+1];
n=n-(y-x+1);
}
int cautare(int a[], int n, int x)//cauta pe x in vecctorul a
{
for(int i=1;i<=n;i++)
if(a[i]==x) return 1;
return 0;
}
void construireR(int a[], int n, int R[], int &m)//construieste R
{
for(int i=1;i<n;i++)
if(asemenea(a[i],a[i+1]))//doua asemena
{
int j=i+1;
while(asemenea(a[i],a[j]) && j<=n) j++;//cat timp sunt asemenea maresc j
for(int k=i;k<j;k++)
if(cautare(R,m,a[k])==0) R[++m]=a[k];
}
}
void stergesecvente(int a[], int &n)//sterge secventele de numere asemenea
{
for(int i=1;i<n;i++)
if(asemenea(a[i],a[i+1]))//doua asemena
{
int j=i+1;
while(asemenea(a[i],a[j]) && j<=n) j++;//cat timp sunt asemenea maresc j
stergij(a,n,i,j-1);//sterg de la i la j-1
i--;
}
}
int main()
{
int X[100], R[100], n,m=0;
citire(X,n);
construireR(X,n,R,m);
stergesecvente(X,n);
if(n>0) afisare(X,n);
else cout<<" X e vid\n";
if(m>0) afisare(R,m);
else cout<<"R e vid\n";
return 0;
}