code
/*
* @brief Remove the duplicate letter from input string
*
* @param [in]str the input str pointer
* @param [out]pOutputStr the output str pointer
* @param [int|out]outLen the inputed output str length and the length of output str
*
* @retval None
*
*/
void dedup(const char *str, char* pOutputStr, int *outLen)
{
int i = 0;
int j = 0;
int k = 0;
if(NULL == str || NULL == pOutputStr ){
printf("The INPUT str || OUTPUT pOutputStr is : NULL !");
return;
}
int stringLen = strlen(str);
for(i = 0; i < stringLen && k < *outLen; i++){
char testingChar = str[i];
for(j = 0; j < k; j++) {
if(pOutputStr[j] == testingChar)
break;
}
if( j == k) {
pOutputStr[k] = testingChar;
k++;
}
}
pOutputStr[k] = '\0';
*outLen = k;
}
int main(){
int outLen = OUT_PUT_ARRAY_LEN;
char outStr[OUT_PUT_ARRAY_LEN + 1];
char *inputStr = "aabbbbcccccdddeeefffffaaaa";
printf("The input string:%s\n", inputStr);
dedup(inputStr, outStr, &outLen);
printf("The output string:%s, the output string Len: %d\n", outStr, outLen);
30,5 96%
dedup(inputStr, outStr, &outLen);
printf("The output string:%s, the output string Len: %d\n", outStr, outLen);
}
~
Makefile :
CC=/opt/codesourcery/arm/bin/arm-linux-gcc
DEST_OBJ := dedup
CFLAGS += -static
OBJ_DIR := .
SRCS := dedup.c
OBJS := $(patsubst %.c, $(OBJ)%.o, $(filter %.c, $(SRCS)))
all release debug: $(DEST_OBJ)
$(DEST_OBJ) : $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(DEST_OBJ)
clean cleanall:
rm -fr $(DEST_OBJ) $(OBJS)
Push Shell :
chmod +x dedup;
adb connect 10.86.60.31;
adb -s 10.86.60.31:5555 remount ;
adb -s 10.86.60.31:5555 push dedup /system/bin;
adb -s 10.86.60.31:5555 shell sync;
Test
其他方法
int GetResult(const char *input, char *output)
{
if(input==NULL || output == NULL)
return -1;
vector<char> char_vec;
vector<char>::iterator it;
while(*input!='\0')
{
for(it=char_vec.begin();it!=char_vec.end();++it)
{
if(*it == *input)
{
break;
}
}
if(it == char_vec.end())
{
char_vec.push_back(*input);
*output++=*input;
}
++input;
}
*output='\0';
return 0;
}
int GetResult2(const char *input, char *output)
{
if(input == 0 || output == 0)
return -1;
int i = 0;
bool ch[129];
for(i = 0; i < 129;i++)
ch[i] = false;
for(i = 0; *input != '\0' ; input++){
if(!ch[*input]){
ch[*input] = true;
*output++ = *input;
}
}
*output = '\0';
return 0;
}