PREFIXES.cpp

PHOTO EMBED

Thu Sep 19 2024 05:50:03 GMT+0000 (Coordinated Universal Time)

Saved by @LizzyTheCatto

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int a;
    cin >> a;
    string n;
    cin >> n;
    int A = 0;
    int B = 0;
    for(int i =0; i < n.size(); i++){
        if(n[i] == 'a'){
            A = A + 1;
        }
        
        if(n[i] == 'b'){
            B = B + 1;
        }
    }
    cout << A << " " << B << " ";
    cout << n.size() / 2 - min(A,B);
    return 0;
}
content_copyCOPY

https://www.programiz.com/cpp-programming/online-compiler/