for_ciklus_C++.cpp

 1  #include <iostream>         // cin, cout
 2  #include <cstdlib>          // srand, rand
 3  #include <ctime>            // time
 4  #include <vector>           // vector
 5  #include <algorithm>        // find
 6  
 7  using namespace std;
 8  
 9  void vector_out(vector<int> vec)
10  {
11      for (const int& i : vec)
12      {
13          cout << i << "  ";
14      }
15      cout << endl;
16  }
17  
18  int main()
19  {
20      setlocale(LC_ALL,"hun");
21  
22      cout << "*************************************************" << endl;
23      cout << "* ÖTÖSLOTTÓ SZIMULÁTOR v1.0 (C)2022, Jacob Gips *" << endl;
24      cout << "*************************************************" << endl;
25      // lottózás
26      vector<int> szamok;
27      vector<int> tippek;
28      vector<int> kihuzott;
29  
30      for(auto i=0;i<90;i++)
31      {
32          szamok.push_back(i+1);
33      }
34      //vector_out(szamok);
35  
36      // most jönnek a lottózó tippjei
37      cout << "\nTippelj meg öt nyerõ számot:" << endl;
38      int tipp;
39      for(auto i=0;i<5;i++)
40      {
41          cout << i+1 <<". tipped: ";
42          cin >> tipp;
43          tippek.push_back(tipp);
44      }
45      // tippek vector rendezése
46      cout << "Tehát a tippjeid emelkedõ számsorrendben:" << endl;
47      sort(tippek.begin(), tippek.end());
48      vector_out(tippek);
49  
50      // most jön a sorsolás
51      cout << "\nA sorsolás eredménye a kihúzás sorrendjében:" << endl;
52      srand(time(NULL));
53      for(auto i=0;i<5;i++)
54      {
55          kihuzott.push_back(rand()%90+1);
56      }
57      // teszteléshez az alábbi sor aktiválható!!!!!!
58      // kihuzott= {10,20,30,40,50};
59      vector_out(kihuzott);
60  
61      // kihuzott vector rendezése
62      cout << "\nA sorsolás eredménye emelkedõ számsorrendben:" << endl;
63      sort(kihuzott.begin(), kihuzott.end());
64      vector_out(kihuzott);
65  
66      // találatszám megállapítása
67      vector<int>::iterator it;           // find függvényhez kell, mivel az egy iterátort ad vissza
68                                          // http://www.inf.u-szeged.hu/~antal/prog1gyak-lev/eloadas/iterator/
69      int keres,talalatszam=0;
70      for(int i=0;i<kihuzott.size();i++)
71      {
72          keres=tippek[i];
73          it=find(kihuzott.begin(), kihuzott.end(), keres);
74          if (it!= kihuzott.end())
75          {
76              talalatszam++;
77          }
78      }
79      cout << "Találatok száma: " << talalatszam << endl;
80  
81      cout << "\nJáték vége!" << endl;
82  
83      return 0;
84  }