Ejemplo n.º 1
0
float find_product_number(string line) {
    string::size_type pos = line.find(";");
    string c = line.substr(0, pos);
    string p = line.substr(pos + 1);

    vector<string> customer, product;

    while (c.find_first_of(",") != string::npos) {
        pos = c.find_first_of(",");
        string temp = c.substr(0, pos);
        customer.push_back(temp);
        c = c.substr(pos + 1);
    }
    customer.push_back(c);

    while (p.find_first_of(",") != string::npos) {
        pos = p.find_first_of(",");
        string temp = p.substr(0, pos);
        product.push_back(temp);
        p = p.substr(pos + 1);
    }
    product.push_back(p);

    vector<Letter *> customer_letter = find_letter(customer);
    vector<Letter *> product_letter = find_letter(product);
    auto M = customer_letter.size();
    auto N = product_letter.size();

    if (M < N) {
        auto diff = N - M;
        for (vector<Letter *>::size_type i = 0; i < diff; ++i) {
            Letter *l = (Letter *) malloc(sizeof(Letter));
            l->letter = 0;
            customer_letter.push_back(l);
        }
    }
    else if (M > N) {
        auto diff = M - N;
        for (vector<Letter *>::size_type i = 0; i < diff; ++i) {
            Letter *l = (Letter *) malloc(sizeof(Letter));
            l->letter = 0;
            product_letter.push_back(l);
        }
    }

    return Hungarian(customer_letter, product_letter);
}
Ejemplo n.º 2
0
void render_screen(int fd, std::string str)
{
    // Clear the screen
    memset(frontstore, 0, sizeof(frontstore));

    auto render_string = [](std::string str, int start_line)
    {
        // The start line, and start x coordinate
        int line = start_line;
        int char_x = 1;
        // Run the entire string, char by char
        for(char& c : str)
        {
            // Find the pixel letter corresponding to the char
            Letter l = find_letter(c);

            // If we overflow this line, by adding it, do a line break
            if(char_x + l.letter_width >= YSIZE)
            {
                char_x = 1;
                line++;
                // If we overflow the screen, skip the rest of the string
                if(line > 2)
                {
                    break;
                }
            }

            // Calculate our y coord, based upon the line, we're in
            int char_y = 0 + line * (LETTER_HEIGHT + 1);
            // Do the actual printing of the character
            put_letter(char_y, char_x, l);
            // Move the size of this letter, and 1 character,
            // before rendering the next character
            char_x += l.letter_width;
            char_x += 1;
        }
        // People who start on the line after us
        return line+1;
    };
    // Write the new string
    int end_line = render_string(str, 0);
    // If the new string did not take up all the space,
    // lets reload some of the old stuff, and draw that
    for(std::string old : old_lines)
    {
        // Only draw, if we're inside the screen
        if(end_line > 2)
        {
            break;
        }
        end_line = render_string(old, end_line);
    }
    // The string we just rendered, is now an old line
    old_lines.push_front(str);
    // Garbage collect old_lines
    while(old_lines.size() > 3)
    {
        old_lines.pop_back();
    }

    // Render!
    scr_frontmap(fd);
}