-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (51 loc) · 1.49 KB
/
Copy pathmain.cpp
File metadata and controls
70 lines (51 loc) · 1.49 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
//
// Created silverstringer on 12.05.19.
//
#include <iostream>
#include <map>
#include <bitset>
#include <vector>
#include <algorithm>
#include <stdlib.h>
using namespace std;
struct Consecutive {
std::map<int, int> elem;
void operator()(int N) {
int result = 0;
int counter = 0;
bool pop_bit;
int temp = N;
while (N) {
pop_bit = N & 1;
N >>= 1;
if (pop_bit) {
counter++;
} else {
result = std::max(result, counter);
counter = 0;
}
result = std::max(result, counter);
}
cout << temp << ":" << result << ":" << std::bitset<16>(temp).to_string() << "\n";
elem.insert(std::make_pair(temp, result));
}
operator std::map<int, int>() { return elem; }
};
int main() {
std::vector<int> number;
int num, numbers;
cin >> num;
for (auto i = 0; i < num; i++) {
cin >> numbers;
number.push_back(abs(numbers));
}
Consecutive s;
std::map<int, int> x = std::for_each(number.begin(), number.end(), s);
// example: std::map<int,int> x = { { 678,2 },{ 111,4 },{34,1},{56,3},{567,3} };
auto max = std::max_element(x.begin(), x.end(),
[](const pair<int, int> &p1, const pair<int, int> &p2) {
return p1.second < p2.second;
});
std::cout << max->second;
return 0;
}