int main() {
  // testBraces("(())");
  // testBraces("(()}");
  testPrefix("++3,4,5", 9);
  testPrefix("-,*,/,15,-,7,+,1,1,3,+,2,+,1,1", 5);
  testPrefix("/,-,*,2,5,*,1,2,-,11,9", 4);
  testPrefix("-,*,/,15,-,7,+,1,1,3,+,2,+,1,1", 5);
  testPrefix("/,-,*,2,5,*,1,2,-,11,9", 4);
}
示例#2
0
int exploreOne(const node* dictionary, const boggleBoard* boggle, point p, int timing) {
    stack stack;
    path path;
    int n = 0;
    int depth, neighbors, i;
    point neighborBuf[8];
    char print[80];
    stack.len = 0;

    path.len = 1;
    path.chain[0] = p;
    path.string[0] = boardLookup(boggle, p);

    if (!testPrefix(dictionary, path.string, 1))
        return 0;

    visit v = {p.x, p.y, 0};
    push(&stack, v);

    while (stack.len) {
        v = pop(&stack);

        p.x = v.x;
        p.y = v.y;
        depth = v.depth;

        path.chain[depth] = p;
        path.string[depth] = boardLookup(boggle, p);
        path.len = depth + 1;

        /* Just print the matches and sort/uniqueify afterwards if we're interested */
        if (lookup(dictionary, path.string, depth + 1)) {
            if (!timing) {
                for (i = 0; i < depth + 1; ++i)
                    print[i] = path.string[i];
                print[i] = '\0';
                printf("%s\n", print);
            }
            n++;
        }

        neighbors = unvisitedNeighbors(boggle, p, neighborBuf, &path);

        for (i = 0; i < neighbors; ++i) {
            path.string[depth + 1] = boardLookup(boggle, neighborBuf[i]);
            if (testPrefix(dictionary, path.string, depth + 1)) {
                v.x = neighborBuf[i].x;
                v.y = neighborBuf[i].y;
                v.depth = depth + 1;
                push(&stack, v);
            }
        }
    }

    return n;
}
示例#3
0
int accept(node* dict, char prefix[], char suffix[], int n) {
  int len = strlen(prefix);
  char newPrefix[len + 2];

  strcpy(newPrefix, prefix);
  newPrefix[len] = suffix[0];
  newPrefix[len + 1] = '\0';

  if (testPrefix(dict, newPrefix))
    return dp(dict, newPrefix, suffix + 1, n);
  else
    return 0;
}
示例#4
0
bool eChatPrefixSpamTester::HasKnownPrefix( tString & out, nTimeRolling & timeOut ) const
{
    eChatLastSaid::PrefixList & prefixes = player_->GetLastSaid().knownPrefixes_;
    eChatLastSaid::Prefix testPrefix( say_.Said(), 0, 0 );
    
    eChatLastSaid::PrefixList::iterator it =
        std::find_if( prefixes.begin(), prefixes.end(), IsPrefixPredicate< eChatLastSaid::Prefix >( testPrefix ) );
    
    if ( it != prefixes.end() )
    {
        // Stop saying that!
        it->timeout_ += se_CalcTimeout( it->score_ ) / 3;
        
        out = se_EscapeColors( it->prefix_ );
        timeOut = RemainingTime( it->timeout_ );
        
        return true;
    }
    
    return false;
}