Skip to content

Instantly share code, notes, and snippets.

@sicknarlo
Created December 17, 2014 15:28
Show Gist options
  • Save sicknarlo/0bdeaa888bdf1ce06460 to your computer and use it in GitHub Desktop.
Save sicknarlo/0bdeaa888bdf1ce06460 to your computer and use it in GitHub Desktop.
[HackerRank] Alternating Characters
/* Shashank likes strings in which consecutive characters are different. For example,
he likes ABABA, while he doesn't like ABAA. Given a string containing characters A and
B only, he wants to change it into a string he likes. To do this, he is allowed to
delete the characters in the string.
Your task is to find the minimum number of required deletions. */
#include<iostream>
#include<string>
using namespace std;
int main(){
int t = 0;
int output[100000];
cin >> t;
for (int i = 0; i < t; i++){
string str;
cin >> str;
int count = 0;
for (int j = 0; j < str.length(); j++){
if (str[j] == str[j + 1]){
str[j + 1] == str[j + 2];
count++;
}
}
output[i] = count;
}
for (int i = 0; i < t; i++){
cout << output[i] << endl;
}
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment