Topic title:
-
Remove repeating characters
-
Given a string, all the characters in the string are removed, the remaining characters are preserved, and the processed string is output. You need to guarantee the order in which characters appear and are case-sensitive.
Detailed Description:
Prototype:
int GetResult (const char *input, char *output)
Input parameters:
The string entered by input
Output parameters (consider whether the memory area pointed to by the pointer is valid):
string of output outputs
return value:
0 successes
-1 Failures and exceptions
Example:
Input: AB a DC Bad , the characters in the red part of the word have already appeared before.
Then: Output ABDC, return 0.
For the subject, very simple, but want to pass almost impossible, this is the usual problem of programming habits, especially pay attention to the judgment of the null pointer! The following code is passed:
int GetResult (const char *input, char *output) {if (input = = NULL | | output = = NULL) {return-1;} int hash[1000] = {0};int i = 0;while (*input! = ') {hash[(*input-' 0 ')]++;if (hash[(*input-' 0 ')] = = 1) {output[i++] = *i Nput;} input++;} Output[i] = ' + '; return 0;}
OJ Test topic--Delete duplicate characters