當前位置: 首頁>>代碼示例>>C++>>正文


C++ std::isdigit方法代碼示例

本文整理匯總了C++中std::isdigit方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::isdigit方法的具體用法?C++ std::isdigit怎麽用?C++ std::isdigit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在std的用法示例。


在下文中一共展示了std::isdigit方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: validWordAbbreviation

 bool validWordAbbreviation(string word, string abbr) {
     int lw = word.size();
     int la = abbr.size();
     int i = 0;
     int j = 0;
     int d;
     while (i < lw && j < la) {
         if (isdigit(abbr[j])) {
             // Leading zero
             if (abbr[j] == '0' && j + 1 < la && isdigit(abbr[j + 1])) {
                 return false;
             }
             d = 0;
             while (j < la && isdigit(abbr[j])) {
                 d = d * 10 + (abbr[j++] - '0');
             }
             if (d == 0) {
                 return false;
             }
             
             i += d;
         } else {
             if (word[i] != abbr[j]) {
                 return false;
             } else {
                 ++i;
                 ++j;
             }
         }
     }
     return i == lw && j == la;
 }
開發者ID:Septemberchar,項目名稱:leetcode-2,代碼行數:32,代碼來源:valid-word-abbreviation_1_AC.cpp

示例2: rdCLArgs

// Called by: main()
void Driver::rdCLArgs(int ac, char *av[])
{
   while (--ac && !help) {
        char cla = '\0';
        if ((*++av)[0] == '-') {
            cla = (*av)[1];
            switch (cla) {
            case 'v':
                verbose = true;
                break;
            case 't':     // use default seed, print block number of each change
                test = true;
                break;
            case 's':                             // use subsequent arg for seed
                if (!isdigit((*++av)[0])) {                       // input error
                    help = true;
                    --ac;
                    break;
                }
                theSeed = strtoul(*av, nullptr, 0);
                --ac;
                break;
            case 'L':
            case 'l':  
                longRun = true;
                break;
            case 'h':
                help = true;
                break;
            default:
                cerr << "ERROR: Bad command line argument" << '\n';
            }
        }
    }
}
開發者ID:jazcap53,項目名稱:memModel,代碼行數:36,代碼來源:driver.cpp

示例3: strlen

// conversion constructor that converts a character string 
// representing a large integer into a HugeInt object
HugeInt::HugeInt( const char *string )
{
   // initialize array to zero
   for ( int i = 0; i <= 29; i++ )
      integer[ i ] = 0;

   // place digits of argument into array
   int length = strlen( string );

   for ( int j = 30 - length, k = 0; j <= 29; j++, k++ )

      if ( isdigit( string[ k ] ) )
         integer[ j ] = string[ k ] - '0';
} // end HugeInt conversion constructor
開發者ID:AlterTiton,項目名稱:bcit-courses,代碼行數:16,代碼來源:Hugeint.cpp

示例4: nextState

int Lexical::nextState( int curState, char input ){
                                    //   L,  D,  ",  \,  .,  +,  -,  *,  /,  >,  <,  !,  =,  &,  |,  {,  },  (,  ),',', ;
    int transitions[STATES][INPUTS] = { { 1,  2,  5, -1,  4,  8,  8,  9,  9, 10, 10, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22},
                                        { 1,  1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1,  2, -1, -1,  3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1,  4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1,  4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
                                        { 5,  5,  7,  6,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5},
                                        { 5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 11, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 11, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 11, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
                                        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1} };
    int next = -1;

    switch( input ){
    case '.':
        next = transitions[curState][POINT];
        break;
    case '\\':
        next = transitions[curState][BACKSLASH];
        break;
    case '\"':
        next = transitions[curState][D_QUOTE];
        break;
    case '+':
        next = transitions[curState][PLUS];
        break;
    case '-':
        next = transitions[curState][MINUS];
        break;
    case '*':
        next = transitions[curState][PROD];
        break;
    case '/':
        next = transitions[curState][DIV];
        break;
    case '>':
        next = transitions[curState][GREATER];
        break;
    case '<':
        next = transitions[curState][LESSER];
        break;
    case '!':
        next = transitions[curState][NOT];
        break;
    case '=':
        next = transitions[curState][EQ];
        break;
    case '&':
        next = transitions[curState][AND];
        break;
    case '|':
        next = transitions[curState][OR];
        break;
    case '{':
        next = transitions[curState][LCB];
        break;
    case '}':
        next = transitions[curState][RCB];
        break;
    case '(':
        next = transitions[curState][LP];
        break;
    case ')':
        next = transitions[curState][RP];
        break;
    case ',':
        next = transitions[curState][COMMA];
        break;
    case ';':
        next = transitions[curState][SEMI_COLON];
    default:
        if( isalpha( input ) or input == '_' ){
            next = transitions[curState][LETTER];
        }
        else if( isdigit( input ) ){
            next = transitions[curState][DIGIT];
        }
        else if( curState == 5 || curState == 6 ){
            next = 5;
        }
        break;
    }

    return next;
}
開發者ID:Blurred-9L,項目名稱:BlurCC,代碼行數:99,代碼來源:Lexical.cpp


注:本文中的std::isdigit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。