2 条题解

  • 0
    @ 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;
    }
    
    
    • 0
      @ 2025-9-14 20:54:18

      按照题意模拟即可。

      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
      	string s;
          cin >> s;
          int ans = 0;
          for (int i = 0; i <= s.size() - 2; i++)
              if (s[i] == 'g' && s[i + 1] == 'j') ans++;
          if (ans >= 2) ans += 9;
          cout << ans << endl;
      	return 0;
      }
      
      • 1

      信息

      ID
      125
      时间
      1000ms
      内存
      256MiB
      难度
      1
      标签
      递交数
      4
      已通过
      3
      上传者