-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathone_thread.cpp
More file actions
50 lines (36 loc) · 950 Bytes
/
Copy pathone_thread.cpp
File metadata and controls
50 lines (36 loc) · 950 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
/*
M25-514 Kirgizov Temurmalik Kutbiddin ugli.
Task 1. One thread simple impl.
*/
#include <iostream>
using namespace std;
unsigned int global_seed;
void my_srand(unsigned int a) { global_seed = a; }
unsigned int my_rand() {
global_seed = 214013 * global_seed + 2531011;
return (global_seed >> 16) & 0x7fff;
}
long calculate_local_maximum(unsigned char *mas, long size) {
my_srand(2025);
for (long i = 0; i < size; i++) {
mas[i] = my_rand() & 0xff;
}
long counter = 0;
for (long i = 1; i < size - 1; i++) {
if (mas[i] >= mas[i - 1] && mas[i] >= mas[i + 1])
counter++;
}
if (mas[0] >= mas[1])
counter++;
if (mas[size - 1] >= mas[size - 2])
counter++;
return counter;
}
int main() {
const long MAS_SIZE = 1000000000;
unsigned char *mas = new unsigned char[MAS_SIZE];
long count = calculate_local_maximum(mas, MAS_SIZE);
cout << "count: " << count << endl;
delete[] mas;
return 0;
}