Find number at certain position

Hello
I have to make a bingo lottery game. So I have two text files with 25 numbers that are random from 1-75 and I push back them into a vector. Two text files called Ticket, where numbers are in 5x5 grid, and Numbers. How do I find if numbers file contain a number on a specific ticket grid position?
1
2
3
4
5
6
7
8
9
10
11
12
13
//Exaple
Ticket //random numbers from 1-75
 1,  2,  3,  4, 5 
 6,  7,  8,  9, 10
11, 12, 13, 14, 15
16, 17, 18, 19, 20
21, 22, 23, 24, 25

Numbers //random numbers from 1-75
1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 11, 12, 13, 14 ,15, 16, 17, 18, 19, 20, 25, 24, 23, 22, 21 

//Output
Edge game: won //Ticket file numbers 1, 5, 21, 25 found in Numbers file 

I know there is std::find, but I am not sure how use that, if you can, to find number given position.
Thank you
closed account (E0p9LyTq)
A couple of examples for how to use std::find:

http://www.cplusplus.com/reference/algorithm/find/
http://en.cppreference.com/w/cpp/algorithm/find
How do I find if numbers file contain a number on a specific ticket grid position?

Are you sure is that what you really want?

Anyway, please consider the following example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <algorithm>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <random>
#include <vector>

constexpr std::size_t GRID_DIM { 5 };

void checkSequenceVsGrid(const std::vector<unsigned>& seq,
                         const std::vector<std::vector<unsigned>>& grid);
void waitForEnter();

int main()
{
    constexpr unsigned MIN_TOCKEN {  1 },
                       MAX_TOCKEN { 75 };

    // Create a random 5 x 5 bingo card with values from 1 to 75.
    // Since values must be unique, we create e sequence of 76 ordered values,
    // then we shuffle them and finally we use them to fill our bi-dimensional
    // std::vector:
    std::vector<unsigned> base(MAX_TOCKEN);
    std::iota(base.begin(), base.end(), MIN_TOCKEN);
    std::mt19937 gen { static_cast<unsigned>(std::chrono::high_resolution_clock::now()
                                                .time_since_epoch()
                                                .count())};
    std::shuffle(base.begin(), base.end(), gen);
    std::vector<std::vector<unsigned>> card(GRID_DIM, std::vector<unsigned>(GRID_DIM));
    auto myit = base.begin();
    for(auto& c : card) {
        std::copy_n(myit, GRID_DIM, c.begin());
        std::advance(myit, GRID_DIM);
    }
    std::cout << "\nYour card:\n";
    for(const auto& a : card) {
        for(const auto& b : a) { std::cout << std::setw(5) << b; }
        std::cout << '\n';
    }

    // Create a random sequence of 25 values from 1 to 75:
    std::cout << "\n\nDraw sequence:\n";
    std::vector<unsigned> draws(GRID_DIM * GRID_DIM);
    std::uniform_int_distribution<unsigned> extr(MIN_TOCKEN, MAX_TOCKEN);
    std::generate(draws.begin(), draws.end(), [&extr, &gen]() { return extr(gen); } );
    for(std::size_t i {1}; i <= draws.size(); ++i) {
        std::cout << std::setw(5) << draws.at(i-1) << '\t';
        if(!(i % GRID_DIM)) { std::cout << '\n'; }
    }
    std::cout << "\n\n";
    
    // Check if n-th value from "draws" match n-th value from "card":
    std::cout << "Checking for matches\n";
    checkSequenceVsGrid(draws, card);
    waitForEnter();
}

void checkSequenceVsGrid(const std::vector<unsigned>& seq,
                         const std::vector<std::vector<unsigned>>& grid)
{
    if(seq.empty() || grid.empty()) { return; }
    for(unsigned row {}, col {}, u {}; u < seq.size(); ++u) {
        if(col == grid.at(row).size()) {
            ++row;
            col = 0;
        }
        std::cout << "Draw n. " << std::setw(2) << u + 1 << " is "
                  << std::setw(2) << seq.at(u)
                  << "; card at (" << row + 1 << ", " << col + 1 << ") is "
                  << std::setw(2) << grid.at(row).at(col) << ". ";
        if(seq.at(u) == grid.at(row).at(col)) { std::cout << "They match.\n"; }
        else                                  { std::cout << "They don't match.\n"; }
        ++col;
    }
}

void waitForEnter()
{
    std::cout << "\nPress ENTER to continue...\n";
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}


Output example:

Your card:
   71   15   13   29   38
   26   52   67   51   12
   74    6   50    1   35
   36   73   40   72    8
    9    2   64   53   28


Draw sequence:
   45      55      17      26      67
   19       8       1      11      69
   68      66      26      71      23
   74      73      73      22      12
   50      54      25      24      49


Checking for matches
Draw n.  1 is 45; card at (1, 1) is 71. They don't match.
Draw n.  2 is 55; card at (1, 2) is 15. They don't match.
Draw n.  3 is 17; card at (1, 3) is 13. They don't match.
Draw n.  4 is 26; card at (1, 4) is 29. They don't match.
Draw n.  5 is 67; card at (1, 5) is 38. They don't match.
Draw n.  6 is 19; card at (2, 1) is 26. They don't match.
Draw n.  7 is  8; card at (2, 2) is 52. They don't match.
Draw n.  8 is  1; card at (2, 3) is 67. They don't match.
Draw n.  9 is 11; card at (2, 4) is 51. They don't match.
Draw n. 10 is 69; card at (2, 5) is 12. They don't match.
Draw n. 11 is 68; card at (3, 1) is 74. They don't match.
Draw n. 12 is 66; card at (3, 2) is  6. They don't match.
Draw n. 13 is 26; card at (3, 3) is 50. They don't match.
Draw n. 14 is 71; card at (3, 4) is  1. They don't match.
Draw n. 15 is 23; card at (3, 5) is 35. They don't match.
Draw n. 16 is 74; card at (4, 1) is 36. They don't match.
Draw n. 17 is 73; card at (4, 2) is 73. They match.
Draw n. 18 is 73; card at (4, 3) is 40. They don't match.
Draw n. 19 is 22; card at (4, 4) is 72. They don't match.
Draw n. 20 is 12; card at (4, 5) is  8. They don't match.
Draw n. 21 is 50; card at (5, 1) is  9. They don't match.
Draw n. 22 is 54; card at (5, 2) is  2. They don't match.
Draw n. 23 is 25; card at (5, 3) is 64. They don't match.
Draw n. 24 is 24; card at (5, 4) is 53. They don't match.
Draw n. 25 is 49; card at (5, 5) is 28. They don't match.

Press ENTER to continue...

cidex, you can just make more structures to better arrange certain strange win conditions.

For example, just have another vector of size 4, with pointers to the corners of the original ticket. Then you can make a check if all numbers found in the corners vector are also all found in the numbers vector.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <vector>

using namespace std;

template<typename T>
void print_matrix(const vector<vector<T>>& v)
{
    for(auto& row : v)
    {
        for(auto& ele : row)
            cout << ele << " ";
        cout << endl;
    }
}

template<typename T>
void print_vec(const vector<T>& v)
{
    for(auto& ele : v)
        cout << ele << " ";
    cout << endl;
}

template<typename T>
void print_deref_vec(const vector<T>& v)
{
    for(auto& ele : v)
        cout << *ele << " ";
    cout << endl;
}


int main() 
{
    int rows = 5;
    int cols = 5;
    vector<vector<int>> ticket;
    ticket.resize(rows, vector<int>(cols,0));
    
    cout << "Initial state of ticket:\n";
    print_matrix(ticket);
    
    vector<int*> corners = { &ticket[0][0], &ticket[0][cols-1], 
                             &ticket[rows-1][0], &ticket[rows-1][cols-1] };
    
    cout << "\nInitial state of corners vector:\n";
    print_vec(corners);
    cout << "\nInitial values of corners vector:\n";
    print_deref_vec(corners);
    
    cout << "\nChanging corners of ticket to 75, 65, 55, 45:\n";
    ticket[0][0] = 75;
    ticket[0][cols-1] = 65;
    ticket[rows-1][0] = 55;
    ticket[rows-1][cols-1] = 45;
    print_matrix(ticket);
    
    cout << "\nCurrent state of corners vector:\n";
    print_vec(corners);
    cout << "\nCurrent values of corners vector:\n";
    print_deref_vec(corners);
    
}


Can run at https://repl.it/repls/PaltryJovialField

Output:
Initial state of ticket:
0 0 0 0 0 
0 0 0 0 0 
0 0 0 0 0 
0 0 0 0 0 
0 0 0 0 0 

Initial state of corners vector:
0xececc0 0xececd0 0xeced40 0xeced50 

Initial values of corners vector:
0 0 0 0 

Changing corners of ticket to 75, 65, 55, 45:
75 0 0 0 65 
0 0 0 0 0 
0 0 0 0 0 
0 0 0 0 0 
55 0 0 0 45 

Current state of corners vector:
0xececc0 0xececd0 0xeced40 0xeced50 

Current values of corners vector:
75 65 55 45 
Topic archived. No new replies allowed.