向前辈致敬 strspn
2013-08-12 19:44
134 查看
把8位的CHAR型数据分解为:前5位和后3位,这样2^5 = 32个CHAR型数+值就可表示所有的CHAR型数据 这样做的好处:在给出子串后,不用比较256次,最多比较32次即可判断出是否一个数在子串中 /*** *int strspn(string, control) - find init substring of control chars * *Purpose: * Finds the index of the first character in string that does belong * to the set of characters specified by control. This is * equivalent to the length of the initial substring of string that * consists entirely of characters from control. The '\0' character * that terminates control is not considered in the matching process. * *Entry: * char *string - string to search * char *control - string containing characters not to search for * *Exit: * returns index of first char in string not in control * *Exceptions: * *******************************************************************************/ int strspn(const char * string, const char * control) { unsigned char map[32] = {0}; size_t count; printf("lx_strspn %s control %s\r\n", string, control); while(*control != 0) { map[*control >> 3] |= (1 << (*control & 7)); control++; } count = 0; while(map[*string >>3] & (1 << (*string & 7))) { printf("%d %d %d \r\n", *string >>3, *string & 7, map[*string >>3]); count++; string++; } return count; }
相关文章推荐
- 图论算法 有图有代码 万字总结 向前辈致敬
- 图论算法 有图有代码 万字总结 向前辈致敬
- 图论算法 有图有代码 万字总结 向前辈致敬
- 第一次写csdn博客,致敬前辈
- 图论算法 有图有代码 万字总结 向前辈致敬
- 图论算法 有图有代码 万字总结 向前辈致敬
- 向前辈致敬致敬
- 图论算法 有图有代码 万字总结 向前辈致敬
- 向前辈致敬 web前端分享
- 向前辈致敬:懂懂和一直特立独行的…
- 图论算法 有图有代码 万字总结 向前辈致敬
- 作为新人、向各位前辈致敬
- 请各位前辈指点迷津
- 向开复致敬
- 80前的前辈,你们都做了些什么?!(二)
- 注意:10种新人最让前辈讨厌
- 母亲节,向天下所有的母亲致敬。
- Visual Studio 2005 SP1集成(整理前辈版本)
- strspn.c
- 《80前的前辈,你们都做了些什么?!》一文的正确解读及是是非非