This is a fairly easy problem but I’m having a problem with one of the test cases. The code is short and pretty simple, but I can’t see where can the mistake be. The code is:
#include <bits/stdc++.h>
using namespace std;
int main(){
string str;
getline(cin, str);
char prev, cur;
int add = 1, total = 1;
for(int i = 1; i < str.length(); i++){
prev = str.at(i-1);
cur = str.at(i);
if(prev == cur){
add++;
}
else{
add = 1;
}
total += add;
}
cout << total;
}
Thanks for your help!