删除重复数组
#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{ int i,j,k;
int length;
cout<<"输入数组长度:";
cin>>length;
int *a=new int[length];
cout<<"输入数组元素:";
for (i=0;i<length;i++)
{
cin >> a[i];
}
for(i=0;i<length;i++)
{
for(j=i+1;j<length;j++)
{
if(a[j]==a[i])
{
for(k=j;k<length;k++)
a[k]=a[k+1];
length--;
}
}
}
cout<<"数组长度:"<<length<<endl;
for (k=0;k<length;k++)
{
cout<<a[k];
}
return 0;
}
时间: 2024-10-13 12:38:23