Created
November 4, 2015 11:02
-
-
Save nbarnold01/98df9731f6dc0af4f92e to your computer and use it in GitHub Desktop.
This file contains 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
#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