mardi 5 mai 2020

How to find a sequence of letter in a given string?

My string is "AAABBAABABB" and i want to get result as

A = 3
B = 2
A = 2
B = 1 
A = 1
B = 2

I have tried to use

for (int i = 0; i < n - 1; i++) {
    if (msg[i] == msg[i + 1]) {
        if(msg[i]==A)
            a++;
        else
            b++;
    }
}

i tried this by it didnt work for me. And dont understand if there any other ways to find it out. Please help me out.

Aucun commentaire:

Enregistrer un commentaire