forked from Programming-Club-IITM/Rust_DC_App_2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscorecard.rs
More file actions
189 lines (170 loc) · 4.76 KB
/
scorecard.rs
File metadata and controls
189 lines (170 loc) · 4.76 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
use std::io;
fn bonus1(arr: &[[i32; 6]; 10], over: usize) -> i32 {
for i in 0..6 {
if arr[over][i] < 4 {
return 0;
}
}
1
}
fn bonus2(arr: &[[i32; 6]; 10], over: usize) -> i32 {
if arr[over][0] == 6 && arr[over][1] == 6 {
2
} else {
0
}
}
fn bonus3(arr: &[[i32; 6]; 10], over: usize) -> i32 {
if arr[over][4] == 6 && arr[over][5] == 6 {
3
} else {
0
}
}
fn maiden(arr: &[[i32; 6]; 10], over: usize) -> i32 {
for i in 0..6 {
if arr[over][i] != 0 {
return 0;
}
}
4
}
fn main() {
let mut overs = [[0; 6]; 10];
let mut max = [0; 10];
let mut score = 0;
let stdin = io::stdin();
for i in 0..10 {
max[i] = 0;
for j in 0..6 {
let mut input = String::new();
stdin.read_line(&mut input).expect("Failed to read line");
overs[i][j] = input.trim().parse().expect("Please type a number!");
score += overs[i][j];
if overs[i][j] > max[i] {
max[i] = overs[i][j];
}
}
}
let mut bonus = [0; 10];
let mut v: Vec<i32> = Vec::new();
for i in 0..10 {
if maiden(&overs, i) == 3 {
bonus[i] = 3;
bonus[i + 1] = 0;
} else if max[i] > 4 {
if bonus1(&overs, i) == 1 {
bonus[i] = 1;
} else {
bonus[i] = bonus2(&overs, i) + bonus3(&overs, i);
}
}
match bonus[i] {
1 => {
for j in i + 1..i + 3 {
if j < 10 {
for k in 0..6 {
score += overs[j][k];
}
v.push(j as i32);
}
}
}
2 => {
v.push(-(i as i32));
for j in 3..6 {
score += overs[i][j];
}
}
3 => {
if i != 9 {
for j in 0..6 {
score += overs[i + 1][j];
v.push((i + 1) as i32);
}
}
}
5 => {
for j in 3..6 {
score += overs[i][j];
}
if i != 9 {
for j in 0..6 {
score += overs[i + 1][j];
v.push((i + 1) as i32);
}
}
v.push(-(i as i32));
}
_ => {}
}
}
for i in 0..10 {
let mut flag = false;
for &val in &v {
if val == i as i32 {
flag = true;
break;
}
}
for j in 0..6 {
if flag {
if overs[i][j] >= 4 {
print!("*{}x2 ", overs[i][j]);
} else {
print!(" {}x2 ", overs[i][j]);
}
} else {
if overs[i][j] >= 4 {
print!("*{} ", overs[i][j]);
} else {
print!(" {} ", overs[i][j]);
}
}
}
println!();
}
if bonus[8] == 1 || bonus[9] == 3 {
let mut extra_over = [0; 6];
for i in 0..6 {
let mut input = String::new();
stdin.read_line(&mut input).expect("Failed to read line");
extra_over[i] = input.trim().parse().expect("Please type a number!");
score += 2 * extra_over[i];
if extra_over[i] >= 4 {
print!("*{}x2 ", extra_over[i]);
} else {
print!(" {}x2 ", extra_over[i]);
}
}
println!();
} else if bonus[9] == 1 {
let mut extra1 = [0; 6];
let mut extra2 = [0; 6];
for i in 0..6 {
let mut input = String::new();
stdin.read_line(&mut input).expect("Failed to read line");
extra1[i] = input.trim().parse().expect("Please type a number!");
score += 2 * extra1[i];
if extra1[i] >= 4 {
print!("*{}x2 ", extra1[i]);
} else {
print!(" {}x2 ", extra1[i]);
}
}
println!();
for i in 0..6 {
let mut input = String::new();
stdin.read_line(&mut input).expect("Failed to read line");
extra2[i] = input.trim().parse().expect("Please type a number!");
score += 2 * extra2[i];
if extra2[i] >= 4 {
print!("*{}x2 ", extra2[i]);
} else {
print!(" {}x2 ", extra2[i]);
}
}
println!();
}
println!("{}", score);
}