Skip to content

Commit 9a716a0

Browse files
antonioialazzoantonioialazzo
authored andcommitted
feat: solve risk-risiko.cpp
1 parent f8f4676 commit 9a716a0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

exercises/risk-risiko.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,36 @@
2727
M 3 vs 3 => blue win
2828
O 2 vs 1 => red win
2929
*/
30+
#include <iostream>
31+
#include <cstdlib>
32+
#include <ctime>
33+
#include <algorithm>
34+
using namespace std;
35+
36+
void throwDices(int *v, size_t n){
37+
for (int i=0; i<n; i++){
38+
v[i] = (rand() % 6) + 1;
39+
}
40+
sort(v, v+n, greater<int>());
41+
}
42+
43+
int main() {
44+
srand(time(nullptr));
45+
int v1[3],v2[3];
46+
char chs[3]= {'N', 'M', 'O'};
47+
throwDices(v1, 3);
48+
throwDices(v2, 3);
49+
cout << "Red dices: " << endl;
50+
for (int i=0; i<3; i++){
51+
cout << v1[i] << " (" << chs[i] << ")"<< endl;
52+
}
53+
cout << "\nBlue dices: " << endl;
54+
for (int i=0; i<3; i++){
55+
cout << v2[i] << " (" << chs[i] << ")"<< endl;
56+
}
57+
58+
printf("\n%3.c%5.c\n", 'R', 'B');
59+
for (int i=0; i<3; i++){
60+
cout << chs[i] << " " << v1[i] << " vs " << v2[i] << " => " << (v1[i]>v2[i] ? "red win" : "blue win" ) << endl;
61+
}
62+
}

0 commit comments

Comments
 (0)