C++ 题解
2025-06-26 14:16:21
发布于:浙江
6阅读
0回复
0点赞
#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
string s;
cin >> s;
unordered_map<char, int> param_count;
int current_pos = 0;
int nop_count = 0;
for (int i = 0; i < s.size(); ) {
char op = s[i];
int params = 0;
if (param_count.find(op) != param_count.end()) {
params = param_count[op];
} else {
int j = i + 1;
while (j < s.size() && islower(s[j])) {
++j;
}
params = j - (i + 1);
param_count[op] = params;
}
int required_pos = ((current_pos + 3) / 4) * 4;
int nops_needed = required_pos - current_pos;
nop_count += nops_needed;
current_pos = required_pos + 1 + params;
i += 1 + params;
}
cout << nop_count << endl;
return 0;
}
这里空空如也
有帮助,赞一个