int RemoveDuplicates(int A[], int n)
{
if (n < 1) return 0;
int j = 0;
int num = A[0];
int count = 1;
int i = 1;
while(++j < n)
if (num == A[j] && count < 2)
{
A[i++] = A[j];
count = 2;
}
else if(num != A[j])
{
num = A[i++] = A[j];
count = 1;
}
return i;
}
#include <iostream>
using namespace std;
void PrintArray(int A[], int n)
{
for (int i = 0; i < n; ++i)
cout << A[i] << ',';
cout << endl;
}
int main(int argc, char** argv)
{
int A[] = {1,1,1,1,1,1,2,2,3,3,3,3,3,3,4,5,6,7,8,8,8,9,9,10,10};
int n = sizeof(A)/sizeof(int);
PrintArray(A, n);
int x = RemoveDuplicates(A, n);
PrintArray(A, x);
return 0;
}