✔ 最佳答案
Here's the answer, but a detailed program complete with test cases is found at the following link:
http://mathmate.brinkster.net/programming.htm
int dedup(int s[], int n)
{
// s is an array of SORTED integers which stores unique values on return
// the return value is the number of unique elements.
int d=0;// number of duplicate elements
int i;
for(i=0;i+1+d<n;i++)
{
while(i+1+d<n && s[i]==s[i+1+d])d++; // increment duplicate count if found
s[i+1]=s[i+1+d];// move unique element into next position
}
return n-d;// number of elements - duplicate = unique
}
2008-01-06 00:39:15 補充:
Here is an example of the output:012223344456667789990 1 2 3 4 5 6 7 8 9there are 10 unique elements