Số cặp từ chẵn trong từ bằng đệ quy

Như yêu cầu đề bài, vd: ABCABCAA ->4; BANANA ->-1;

em code the nay nhung ko biet sai cho nao, moi ngui xem giup em a

   

int isEvenWord(string word) {
    


int n=word.length();

string chuoi=word;

if(n%2==1) return -1;

int i=0;

char kt=word[n];

if(kt==word[i])
{
    word[i]='\0'; word[n]='\0'; return isEvenWord(word)+1;
}
else if(kt!=word[i++] && i<n) 
{
    return isEvenWord(word);
}
else if(i==n) return -1;
else if(word[0]=='\0') return 0;


}

std::string không có '\0' đâu.

3 Likes

nó khi là time error ạ, em nghĩ là sai ở chỗ int i=0, mà em ko biết sửa sao

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?