2727 M 3 vs 3 => blue win
2828 O 2 vs 1 => red win
2929*/
30+
31+ #include < iostream>
32+ #include < cstdlib>
33+ #include < string>
34+ #include < chrono>
35+ #include < algorithm>
36+
37+ using namespace std ;
38+
39+ const int NUM_DICES_FOR_USER = 3 ;
40+ const short int RED_WIN = 1 ;
41+ const short int BLUE_WIN = -1 ;
42+ const unsigned short int FACES_DICES = 6 ;
43+
44+ unsigned int * generateDicesNumber ();
45+ void compareValue (unsigned int * dices);
46+ void showDices (unsigned int * dices);
47+
48+ int main () {
49+ unsigned int seed = static_cast <unsigned int >(
50+ chrono::steady_clock::now ().time_since_epoch ().count ()
51+ );
52+ srand (seed);
53+
54+ unsigned int * dices = generateDicesNumber ();
55+
56+ sort (dices, dices+NUM_DICES_FOR_USER);
57+ sort (dices+NUM_DICES_FOR_USER, dices+(NUM_DICES_FOR_USER*2 ));
58+
59+ showDices (dices);
60+ compareValue (dices);
61+
62+ free (dices);
63+ }
64+
65+ unsigned int * generateDicesNumber (){
66+ unsigned int * dices = new unsigned int ;
67+ for (int i = 0 ; i < NUM_DICES_FOR_USER*2 ; i++) dices[i] = rand () % FACES_DICES + 1 ;
68+ return dices;
69+ }
70+
71+ void compareValue (unsigned int * dices) {
72+ cout << endl << " R B" ;
73+
74+ for (int i = NUM_DICES_FOR_USER-1 ; i >= 0 ; i--) {
75+ cout << endl << " N " << dices[i] << " vs " << dices[i+NUM_DICES_FOR_USER];
76+ if (dices[i] > dices[i+NUM_DICES_FOR_USER]) cout << " => RED WIN" ;
77+ else cout << " => BLUE WIN" ;
78+ }
79+ cout << endl;
80+ }
81+
82+ void showDices (unsigned int * dices){
83+ cout << " \n Blue dices: " << endl;
84+ for (int i = NUM_DICES_FOR_USER*2 -1 ; i >= 0 ; i--) {
85+ if (i == 2 ) cout << " \n\n Red dices: " << endl;
86+ cout << dices[i] << endl;
87+ }
88+ }
0 commit comments