#include<iostream>
using namespace std;
int Cllcdigital(char *str)
{
if(NULL == str){
return 0;
}
int i = 0;
int size = 0;
int count[256] ={0};
char *sd = NULL;
sd = str;
while(*sd != '\0'){
count[*sd] = count[*sd] +1;
sd++;
}
for(i = '0';i<= '9';i++)
{
size += count[i];
}
return size;
}
int main()
{
int size = 0;
char str[] = "he1234llo,0909";
size = Cllcdigital(str);
cout << size <<endl;
return 0;
}
运行结果:
8
Press any key to continue
体会:
有点类似哈希算法的思想,想象有256个桶 ,
来一个元素,就将它放入桶中,每个桶中加一
就可求出