-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLC2844.cpp
More file actions
55 lines (48 loc) · 1.42 KB
/
LC2844.cpp
File metadata and controls
55 lines (48 loc) · 1.42 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
#include <string>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
class Solution {
public:
int minimumOperations(string num) {
auto cmp = [](int a, int b) { return a > b; };
priority_queue<int, vector<int>, decltype(cmp)> res(cmp);
if(num == "0") return 0;
//5结尾 允许25 75,0结尾 允许00 50
vector<int> v; v.reserve(num.size());
for(char ch : num) {
v.push_back(ch - '0');
}
auto itt = v.rbegin();
auto possileRes = 0;
auto baseEnd = 0;
for(auto it = itt; it != v.rend(); ++it,++baseEnd){
possileRes = baseEnd;
while(it != v.rend()){
if(*it != 5 && *it != 0){
++possileRes;++it;
continue;
}
break;
}
int end = *it;
for(; it != v.rend(); ++possileRes,++it){
if((end == 0 && (*it == 5 || *it == 0)) || (end == 5 && (*it == 2 || *it == 7))) {
res.push(possileRes);
}
}
}
return res.top();
}
};
int main() {
Solution solution;
// 第一个测试用例
string num1 = "100100100";
cout << solution.minimumOperations(num1) << endl;
// 第二个测试用例
string num2 = "1001001001";
cout << solution.minimumOperations(num2) << endl;
return 0;
}