Can someone please figure out the mistake?

Revision en1, by Arcer, 2024-05-30 14:36:00

I was just trying the problem 1941C - Рудольф и некрасивая строка and the language used was C++. This is my code, 263228103

#include <bits/stdc++.h>
using namespace std;
int main() {
    int t, n, c = 0;
    cin >> t;
    string s, s1 = "map", s2 = "pie", s3 = "mapie";
    for (int i = 0; i < t; i++) {
        cin >> n;
        cin >> s;
        for (int j = 0; j < n - 2; j++) {
            if (s.find(s3) != string::npos) {
                c++;
                s.erase(s.begin() + s.find(s3) + 2);
            }
            if (s.find(s1) != string::npos) {
                c++;
                s.erase(s.begin() + s.find(s1) + 1);
            }
            if (s.find(s2) != string::npos) {
                c++;
                s.erase(s.begin() + s.find(s2) + 1);
            }
        }
        cout << c << endl;
        c = 0;
    }
}

It passed all my tests but somehow it gets a Wrong answer at testcase 3. Can someone please figure out the mistake made?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Arcer 2024-05-30 14:36:00 1056 Initial revision (published)