-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.cpp
More file actions
55 lines (45 loc) · 1019 Bytes
/
4.cpp
File metadata and controls
55 lines (45 loc) · 1019 Bytes
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
#include "iostream"
#include "random"
#include "chrono"
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
void FillArr(int *a,int n) {
std::uniform_int_distribution<int> dist(1,100);
for (int i = 0; i < n; i++) {
a[i] = dist(rng);
}
}
int IdxFind(int* a,int n) {
int last_idx = -1;
int max_val = -1;
for (int i = 0; i < n; i++) {
if (abs(a[i]) >= max_val) {
max_val = abs(a[i]);
last_idx = i;
}
}
return last_idx;
}
void Solution(const int* a, const int n,int lst_idx) {
long long prod = 1;
if (lst_idx == 0 || lst_idx < 0) {
std::cout<< 0 << "\n";
}else {
for (int i = 0; i < n; i++) {
prod *= a[i];
}
}
std::cout << prod << "\n";
}
void solve() {
int n;
std::cin>>n;
auto* arr = new int[n];
FillArr(arr, n);
int idx = IdxFind(arr, n);
Solution(arr, n,idx);
delete[] arr;
}
int main() {
solve();
return 0;
}