bool isMatch(const char *s, const char *p) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function 
     while(true) {
         if (*s=='\0' && *p=='\0') {
             return true;
         }
         if (isSingle(p)) {
             if (!match_single(s, p)) {
                 return false;
             }
             s++;
             p++;
         }
         else {
             if (isMatch(s, p+2)) {
                 return true;
             }
             while(match_single(s, p)){
                 if (isMatch(s+1, p+2)) {
                     return true;
                 }
                 s++;
             }
             return false;
         }
     }
 }
示例#2
0
/**
 * Extend a match as far as you can
 * @param mt the single match to extend
 * @param text the entire UTF-16 text of the new version
 * @param v the new version
 * @param log the log to record errors in
 * @return the extended/unextended match
 */
match *match_extend( match *mt, UChar *text, int v, plugin_log *log )
{
    match *last = mt;
    match *first = mt;
    do
    {
        //match_verify_end( first );
        match *mt2 = (match_extendible(mt))?match_clone(mt,log):NULL;
        if ( mt2 != NULL )
        {
            int distance = 1;
            //match_verify_end( first );
            if ( match_restart(mt2,v,log) )
            {
                do  
                {
                    if ( match_single(mt2,text,v,log,0) && match_follows(last,mt2) )
                    {// success
                        match_append(last,mt2);
                        mt = last = mt2;
                        break;
                    }
                    else 
                    {// failure: reset and move to next position
                        if ( distance < KDIST )
                        {
                            if ( match_restart(mt2,v,log) )
                            {
                                distance++;
                            }
                            else
                            {
                                match_dispose( mt2 );
                                mt = NULL;
                                break;
                            }
                        }
                        else    // give up
                        {
                            match_dispose( mt2 );
                            last->next = NULL;
                            last = NULL;
                            break;
                        }
                    }
                }
                while ( distance <= KDIST );
            }
            else
            {
                match_dispose( mt2 );
                mt = NULL;
            }
        }
        else
            mt = NULL;
    } while ( last == mt );
    //match_verify_end( first );
    return first;
}