* Binary Insert Sort
*/
void Bin_Insert_Sort( int a[], int length )
{
for ( int i=1i<lengthi++ )
{
// If the adjacent has been order
if ( a[i] >a[i-1] )
{
continue
}
int low = 0
int high = i-1
int temp = a[i]
// Search the position for insert
while( low <= high )
{
int mid = (low+high)/2
if ( temp <a[mid] )
{
high = mid-1
}
else if ( temp >a[mid] )
{
low = mid+1
}
else
{
break
}
} // End of "while(low<=high)"
// The position after move back
int j = i
while ( j >= low )
{
a[j--] = a[j-1]
}
a[low] = temp // Insert the value
} // End of "for(int i=1i<lengthi++)"
} /* End of Bin_Insert_Sort() */
#include <stdio.h>int GetChReCnt(char *s, char ch)
{
char *p = s
char *q
int ret = 0
int n
while(*p)
{
while(*p &&*p!=ch)
{
p++
}
n = 0
while(*p &&*p==ch)
{
n++
p++
}
if(n>=2)
ret++
}
return ret
}
int main()
{
char* str="00320000104asd00d"
char *test = "0200304000050700080000000420715000"
printf("零的重复次数为:%d\n", GetChReCnt(str, '0'))
printf("零的重复次数为:%d\n", GetChReCnt(test, '0'))
return 0
}