May 6, 2023
Решение задачи
int main()
{
int a[100];
int n=10;
int i, j, count=0;
srand(time(NULL));
for (i = 0; i < n; i++)
{
a[i]=rand()%20;
cout<<setw(4)<<a[i];
}
cout<<endl;
for (i = 0; i < n; i++)
{
count=1;
for (j=i+1; j<n; j++)
{
if (a[j] == a[i])
count++;
}
if (count > 2)
{
int one=a[i];
for (j=i; j<n; j++)
{
if (a[j]==one)
{
// удаляем
for (int k=j+1; k<n; k++)
{
a[k-1]=a[k];
}
n--;
j--;
}
}
i--;
}
}
if (n==0)
cout<<"empty array"<<endl;
else
for (int p = 0; p < n; p++)
{
cout<<setw(4)<<a[p];
}
cout<<endl;
getch();
return 0;
}