2014 Huawei Machine Test (i)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.