コード例 #1
0
 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;
 }
コード例 #2
0
ファイル: driver.cpp プロジェクト: jazcap53/memModel
// 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';
            }
        }
    }
}
コード例 #3
0
ファイル: Hugeint.cpp プロジェクト: AlterTiton/bcit-courses
// 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
コード例 #4
0
ファイル: Lexical.cpp プロジェクト: Blurred-9L/BlurCC
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;
}