2014 Huawei Machine Test (i)
/**************************************************************************************************//Huawei 2014 School Recruit Machine Questions Enter a string of lowercase letters (A~Z) through the keyboard. Write a string filter to filter out characters that are not the first occurrence if multiple identical characters appear in the string. For example, the string "ABACACDE" filter result is "ABCDE". Required implementation function: void Stringfilter (const char *PINPUTSTR, long Linputlen, Char *poutputstr); "Input" PINPUTSTR: input string Linputlen: input string Length "Output" POUTPUTSTR: The output string, the space has been opened up, and the input string, such as long; "note" Only need to complete the function algorithm, the middle does not need any IO Input output sample input: "DEEFD" Output: "def" input: "AFAFAFAF" output : "AF" Input: "PPPPPPPP" Output: "P" main function has been hidden, here to retain the user's Test portal, here to test your implementation function, you can call printf printout currently you can use other methods to test, as long as the final program can be executed correctly, The function implementation can be arbitrarily modified, but do not change the function prototype. Make sure that the compile run is not affected. /***********************************************************************/#define _crt_secure_no_warnings# Include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h>void stringfilter (const char *PINPUTSTR, long Linputlen, Char *poutputstr) {Char flag[26];memset (flag, 0, 26);//all set to 0assert (pinputstr! = NULL && Linputlen! = 0); int i = 0;const char *p = PI NputStr;while (*p! = ')} {if (flag[(*p-' a ')]) {p++;} else{poutputstr[i++] = *p;flag[*p-' a '] = 1;//Identifies the character that has occurred, the occurrence is set to 1, the 0p++ is not present;}} Poutputstr[i] = ' + ';//The end of the string is appended with the Terminator}void Main ()//test Case {char str[1024] = {0};char buf[1024] = {0};gets (str); int length = s Trlen (str); Stringfilter (str,length,buf);p rintf ("%s\n", buf); System ("Pause");}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
2014 Huawei Machine Test (i)