- P125's solution
-
题解P125
- @ 2025-12-2 19:19:26
按题意直接模拟即可。
AC code:
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int ans = 0;
int n = s.size();
for (int i = 0; i <= n - 2; i++) {
if (s[i] == 'g' && s[i+1] == 'j') {
ans++;
}
}
if (ans == 0) {
cout << "0" << endl;
} else {
string result = "1" + to_string(ans - 1);
string f;
for (char c : result) {
if (c != '0') {
f += c;
}
}
if (f.empty()) {
cout << "0" << endl;
} else {
cout << f << endl;
}
}
return 0;
}