[Huawei machine trial exercise questions] 15. Delete duplicate characters/delete duplicate strings, Huawei exercises
Question
Title: delete duplicate characters. Given a string, remove all redundant characters in the string that have already been duplicated. Keep the remaining characters and output the processed string. Ensure the order in which the characters appear and are case sensitive. Description: interface prototype: int GetResult (const char * input, char * output) input parameter: String output parameter of input (whether the Pointer Points to the memory zone is valid ): output string return value: 0 success-1 failure and exception example: input: abadcbad, then the red part of the word has appeared before. Then: Output abdc, return 0. Knowledge Point: Use VS2005 for engineering environment Source: software training camp maintainer: d00191780 exercise stage: elementary
Code
/* ------------------------------------- * Date: 2015-06-30 * Author: SJF0115 * Subject: delete duplicate characters/delete duplicate strings * Source: Huawei computer license */# include <stdio. h> # include <string. h>/* Description specifies a string to delete all redundant characters in the string that have been repeated with the previous one. The remaining characters are retained and the processed strings are output. Ensure the order of characters. Prototype int GetResult (const char * input, char * output) input Param input string Output Param output string Return Value 0 success-1 failure and exception */int GetResult (const char * input, char * output) {if (input = NULL | output = NULL) {return-1;} // if int size = strlen (input ); // number of statistical characters: int hash [256] = {0}; int index = 0; for (int I = 0; I <size; ++ I) {// determine whether there has been an if (hash [input [I] = 0) {output [index ++] = input [I];} // if ++ hash [input [I];} // for output [index] = '\ 0'; return 0 ;}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.