Arcer's blog

By Arcer, history, 2 months ago, In English

I was just trying the problem 1941C - Rudolf and the Ugly String 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?

Full text and comments »

  • Vote: I like it
  • -3
  • Vote: I do not like it