zoukankan      html  css  js  c++  java
  • 向前辈致敬 strspn

    把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 '' 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
    ", 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 
    ", *string >>3, *string & 7, map[*string >>3]);
            count++;
            string++;
        }
    
        return count;
    }



  • 相关阅读:
    Qt 主窗口与子窗口之间传值
    Qt 如何使窗体初始最大化
    C++ strcmp与strncmp的比较
    Qt 状态栏(statusbar)的使用
    C++中的补零
    Qt QString转char[]数组
    PAT基础6-9
    PAT基础6-8
    PAT基础6-6
    PAT基础6-7
  • 原文地址:https://www.cnblogs.com/riskyer/p/3253736.html
Copyright © 2011-2022 走看看