Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#import <Foundation/Foundation.h>
int deletionsRequiredForString (char buffer[], int length) {
int deletions = 0;
if (length > 1) {
char previousChar = buffer[0];
for (int i = 1; i < length; i ++) {
char currentChar = buffer[i];
if (currentChar == previousChar) {
deletions++;
} else {
previousChar = currentChar;
}
}
}
return deletions;
}
int main (int argc, const char * argv[]) {
int numberOfWords;
scanf("%d", &numberOfWords);
char buffer[100000];
for (NSInteger i = 0; i < numberOfWords; i ++){
int length = 0;
scanf("%100000s%n",buffer,&length);
printf("%d\n", deletionsRequiredForString(buffer,length));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.