B - Quizzes Editorial by evima


Use a looping control flow like for statement and calculate the score just as the problem statement instructs, then you will obtain AC.

Sample Code (C++)

#include <iostream>
using namespace std;
int main(){
    int n, x;
    string s;
    cin >> n >> x >> s;
    for(char c : s){
        if(c == 'o') x++;
        else if(x) x--;
    }
    cout << x << endl;
}

Sample Code (Python)

N, X = map(int, input().split())
S = input()
for s in S:
    if s == 'o':
        X += 1
    elif X:
        X -= 1
print(X)

posted:
last update: