Created
December 17, 2014 15:28
-
-
Save sicknarlo/0bdeaa888bdf1ce06460 to your computer and use it in GitHub Desktop.
[HackerRank] Alternating Characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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