#include <iostream>
#include <string.h>
using namespace std;
void replace(int *pa,int n)
{
int *arr = new int[n];
arr[0] = pa[0];
int k=0;
for(int i=0;i<n;i++)
{
if(arr[k] == pa[i])
continue;
else
{
k++;
arr[k] = pa[i];
}
}
memset(pa,0,n*4);
for(int i=0;i<k;i++)
{
pa[i] = arr[i];
}
delete[] arr;
}
int main()
{
int arr[] = {1,1,1,2,2,2,1,1,5,5,7,7,0};
replace(arr,sizeof(arr)/sizeof(int));
int i =0;
while(arr[i] != 0)
{
cout<<arr[i]<<‘ ‘;
i++;
}
cout<<endl;
return 0;
}
时间: 2024-12-25 10:17:41